tokensafe 4.6.3 → 4.6.4
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 +38 -5
- package/hooks/claude_code_hook.py +22 -0
- package/hooks/kimi_hook.py +20 -0
- package/hooks/session_start.py +8 -0
- 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 +22 -3
- package/src/auto_inject.py +517 -0
- package/src/cli.py +119 -5
- package/src/command_sanitizer.py +54 -0
- package/src/guard.py +63 -10
- package/src/mcp_server.py +10 -1
- package/src/paths.py +58 -0
- package/src/retrofit.py +91 -4
- package/src/savings.py +81 -0
- package/src/scaffold.py +190 -8
- package/src/session_brief.py +154 -0
- package/src/telemetry_sync.py +93 -25
- package/src/version_checker.py +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/README.md
CHANGED
|
@@ -204,10 +204,42 @@ Why TokenSafe agents ship working code on the first pass without burning quotas
|
|
|
204
204
|
|
|
205
205
|
Deeper mechanics (language matrix, AST syntax trees, cache tiers, governor) live in [docs/ARCHITECTURE.md](docs/ARCHITECTURE.md).
|
|
206
206
|
|
|
207
|
+
## What happens on the first prompt
|
|
208
|
+
|
|
209
|
+
You install TokenSafe, open a project in your agent, and the first turn does the wiring:
|
|
210
|
+
|
|
211
|
+
1. **Detect** the stack (React/Vue + Vite, FastAPI, Go/Gin|Chi, or nothing supported).
|
|
212
|
+
2. **Activate** the adapters:
|
|
213
|
+
* frontend — `tokensafe dev` serves OUMV from an inline Vite config; **no file in the
|
|
214
|
+
repository changes**;
|
|
215
|
+
* FastAPI — a global `~/.tokensafe/pyhooks/sitecustomize.py` mounts `mount_tokensafe(app)`
|
|
216
|
+
when the server runs through `tokensafe run-backend uvicorn ...`;
|
|
217
|
+
* Go — one `AutoMount()` line between `tokensafe:oumv` markers, byte-exact backup in
|
|
218
|
+
`~/.tokensafe/inject/`, `go build` validated, `tokensafe inject --revert` restores it.
|
|
219
|
+
3. **Brief the agent** — a short routing block (hook context and MCP `instructions`) says which
|
|
220
|
+
stack is worked through OUMV and which through the TokenSafe tools. Nothing is written into
|
|
221
|
+
the repository by the brief.
|
|
222
|
+
|
|
223
|
+
```bash
|
|
224
|
+
tokensafe inject --status # what would be wired, and where
|
|
225
|
+
tokensafe inject --dry-run # same, but explicit
|
|
226
|
+
tokensafe inject # apply the safe parts (config + Python autoload + Go line)
|
|
227
|
+
tokensafe inject --revert # restore the Go entrypoint byte-for-byte
|
|
228
|
+
tokensafe create shop --template react-fastapi # greenfield with everything pre-wired
|
|
229
|
+
tokensafe oumv doctor # readiness: adapter installed? runtime live? blocking reasons
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Full matrix and details: [docs/OUMV.md](docs/OUMV.md).
|
|
233
|
+
|
|
207
234
|
## Benchmarks
|
|
208
235
|
|
|
209
236
|
### Agent Usability Benchmarks (AUB) — Full-Stack Agent Velocity
|
|
210
237
|
|
|
238
|
+
> ⚠️ **Simulated, not measured.** These AER figures are computed from fixture traces in the
|
|
239
|
+
> benchmark harnesses (the 12-assertion oracles are real; the agent turns/tokens are not).
|
|
240
|
+
> A measured three-arm run (no TokenSafe / TokenSafe / OUMV) is the next benchmark milestone
|
|
241
|
+
> — until it lands, treat this table as a model, not as a product claim.
|
|
242
|
+
|
|
211
243
|
Beyond file slicing, TokenSafe's agent-native ecosystem eliminates architectural friction, state pollution, and compiler loops for autonomous coding agents across frontend and backend:
|
|
212
244
|
|
|
213
245
|
| Ecosystem Stack | Target Package | Baseline vs. TokenSafe | Autonomous Efficiency Ratio (AER) | Token Savings | Turns to Green | State Safety |
|
|
@@ -438,7 +470,7 @@ All hook adapters fail open: an internal error never stalls your agent. Failures
|
|
|
438
470
|
| `oumv_status` | Status, capabilities, and connection health of frontend/backend OUMV runtimes with hybrid fallback mode |
|
|
439
471
|
| `oumv_observe` | Progressive runtime observation (L0 pulse, L1 surface, L2 detail) with out-of-the-box static AST fallback |
|
|
440
472
|
| `oumv_understand` | Query runtime causality, state dependencies, and backend route mappings |
|
|
441
|
-
| `oumv_mutate` |
|
|
473
|
+
| `oumv_mutate` | OCC-guarded source edits (mandatory `expectedVersion`, path jail, syntax pre-flight, backup) |
|
|
442
474
|
| `oumv_verify` | Transactional verification and state invariant assertions |
|
|
443
475
|
</details>
|
|
444
476
|
|
|
@@ -541,12 +573,13 @@ TokenSafe integrates with the [OUMV Protocol](https://github.com/tokensafe-dev/o
|
|
|
541
573
|
- **Out-of-the-Box Stack Detection**: TokenSafe automatically detects your application stack (`package.json`, `go.mod`, `pyproject.toml`, Vite, Next.js, FastAPI, Gin) and configures agent tooling dynamically.
|
|
542
574
|
- **Level 1 Static AST Fallback**: When live dev-servers are offline, `oumv_observe` and `oumv_understand` gracefully fall back to zero-config static AST component trees and route maps with evidence tracking.
|
|
543
575
|
- **Consolidated Adapters**:
|
|
544
|
-
- **Frontend**:
|
|
576
|
+
- **Frontend**: `tokensafe-ui/react`, `tokensafe-ui/vue`, and the zero-footprint Vite bridge (`tokensafe-ui/vite`) with a session token stored in the per-workspace descriptor (`~/.tokensafe/runtimes/<hash>.json`, mode 0600).
|
|
545
577
|
- **Backend**: Go (`gin`, `chi`, `stdhttp`) and Python (`fastapi`, `sqlalchemy`) in [`tokensafe-backend`](https://github.com/tokensafe-dev/tokensafe-backend).
|
|
546
|
-
- **
|
|
547
|
-
- **
|
|
578
|
+
- **Guarded Mutations, Enabled by Default**: `oumv_mutate` works out of the box 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`.
|
|
579
|
+
- **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.
|
|
580
|
+
- **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.
|
|
548
581
|
|
|
549
|
-
More documentation: [docs/
|
|
582
|
+
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)
|
|
550
583
|
|
|
551
584
|
## Development and License
|
|
552
585
|
|
|
@@ -73,6 +73,17 @@ def handle(event: str, payload: dict, agent: str = AGENT) -> dict:
|
|
|
73
73
|
)
|
|
74
74
|
except Exception:
|
|
75
75
|
pass
|
|
76
|
+
# Routing brief: which stack is worked through OUMV vs TokenSafe tools.
|
|
77
|
+
try:
|
|
78
|
+
from src.paths import is_project_root as _is_project_root
|
|
79
|
+
from src.session_brief import build_workspace_brief
|
|
80
|
+
cwd_for_brief = str(payload.get("cwd") or os.getcwd())
|
|
81
|
+
if _is_project_root(cwd_for_brief):
|
|
82
|
+
routing = build_workspace_brief(cwd_for_brief, include_live=True)
|
|
83
|
+
if routing:
|
|
84
|
+
extra = f"{extra}\n\n{routing}"
|
|
85
|
+
except Exception:
|
|
86
|
+
pass
|
|
76
87
|
try:
|
|
77
88
|
from src.burn_monitor import get_burn_warnings
|
|
78
89
|
burn_warn = get_burn_warnings(
|
|
@@ -136,6 +147,17 @@ def handle(event: str, payload: dict, agent: str = AGENT) -> dict:
|
|
|
136
147
|
)
|
|
137
148
|
|
|
138
149
|
transcript_path = str(payload.get("transcript_path") or "")
|
|
150
|
+
# Routing brief: which stack is worked through OUMV vs TokenSafe tools.
|
|
151
|
+
try:
|
|
152
|
+
from src.paths import is_project_root as _is_project_root
|
|
153
|
+
from src.session_brief import build_workspace_brief
|
|
154
|
+
cwd_for_brief = str(payload.get("cwd") or os.getcwd())
|
|
155
|
+
if _is_project_root(cwd_for_brief):
|
|
156
|
+
routing = build_workspace_brief(cwd_for_brief, include_live=True)
|
|
157
|
+
if routing:
|
|
158
|
+
extra = f"{extra}\n\n{routing}"
|
|
159
|
+
except Exception:
|
|
160
|
+
pass
|
|
139
161
|
try:
|
|
140
162
|
from src.burn_monitor import get_burn_warnings
|
|
141
163
|
burn_warn = get_burn_warnings(
|
package/hooks/kimi_hook.py
CHANGED
|
@@ -55,6 +55,16 @@ def handle(event: str, payload: dict) -> dict:
|
|
|
55
55
|
extra = f"{extra}\n\n{guard}"
|
|
56
56
|
except Exception:
|
|
57
57
|
pass
|
|
58
|
+
try:
|
|
59
|
+
from src.paths import is_project_root as _is_project_root
|
|
60
|
+
from src.session_brief import build_workspace_brief
|
|
61
|
+
kimi_cwd = str(payload.get("cwd") or os.getcwd())
|
|
62
|
+
if _is_project_root(kimi_cwd):
|
|
63
|
+
routing = build_workspace_brief(kimi_cwd, include_live=True)
|
|
64
|
+
if routing:
|
|
65
|
+
extra = f"{extra}\n\n{routing}"
|
|
66
|
+
except Exception:
|
|
67
|
+
pass
|
|
58
68
|
try:
|
|
59
69
|
from src.burn_monitor import get_burn_warnings
|
|
60
70
|
burn_warn = get_burn_warnings(
|
|
@@ -116,6 +126,16 @@ def handle(event: str, payload: dict) -> dict:
|
|
|
116
126
|
f"(TokenSafe: compacted ~{meta['saved_tokens']} prompt tokens, "
|
|
117
127
|
f"-{meta.get('reduction_pct', 0)}% — original intent preserved.)"
|
|
118
128
|
)
|
|
129
|
+
try:
|
|
130
|
+
from src.paths import is_project_root as _is_project_root
|
|
131
|
+
from src.session_brief import build_workspace_brief
|
|
132
|
+
kimi_cwd = str(payload.get("cwd") or os.getcwd())
|
|
133
|
+
if _is_project_root(kimi_cwd):
|
|
134
|
+
routing = build_workspace_brief(kimi_cwd, include_live=True)
|
|
135
|
+
if routing:
|
|
136
|
+
extra = f"{extra}\n\n{routing}"
|
|
137
|
+
except Exception:
|
|
138
|
+
pass
|
|
119
139
|
try:
|
|
120
140
|
from src.burn_monitor import get_burn_warnings
|
|
121
141
|
burn_warn = get_burn_warnings(
|
package/hooks/session_start.py
CHANGED
|
@@ -122,6 +122,14 @@ def main():
|
|
|
122
122
|
extra.append(oumv_brief)
|
|
123
123
|
except Exception:
|
|
124
124
|
pass
|
|
125
|
+
# Routing brief: what goes through OUMV, what goes through TokenSafe tools.
|
|
126
|
+
try:
|
|
127
|
+
from src.session_brief import build_workspace_brief
|
|
128
|
+
routing = build_workspace_brief(workspace_root, include_live=True)
|
|
129
|
+
if routing:
|
|
130
|
+
extra.append(routing)
|
|
131
|
+
except Exception:
|
|
132
|
+
pass
|
|
125
133
|
if extra:
|
|
126
134
|
directives = f"{directives}\n\n" + "\n".join(extra)
|
|
127
135
|
except Exception:
|
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
|
-
"version": "4.6.
|
|
3
|
+
"version": "4.6.4",
|
|
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.4",
|
|
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.4",
|
|
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/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.4",
|
|
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.4",
|
|
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.4",
|
|
43
43
|
"runtimeHint": "uvx",
|
|
44
44
|
"transport": {
|
|
45
45
|
"type": "stdio"
|
package/src/adapter_core.py
CHANGED
|
@@ -459,6 +459,15 @@ def _extract_path(tool_input: Dict[str, Any]) -> str:
|
|
|
459
459
|
|
|
460
460
|
_NUDGE_GC_AGE_SEC = 7 * 86400
|
|
461
461
|
|
|
462
|
+
# Hosts whose PreToolUse schema documents additionalContext, so an edit-time nudge
|
|
463
|
+
# can be delivered without a permissionDecision. ZCode/Kimi keep read-only nudges.
|
|
464
|
+
_OUMV_EDIT_NUDGE_AGENTS = ("claude_code", "claude")
|
|
465
|
+
|
|
466
|
+
|
|
467
|
+
def _oumv_edit_nudge_enabled() -> bool:
|
|
468
|
+
"""Default-on, opt-out in the FileState style: TOKENSAFE_OUMV_EDIT_NUDGE=0."""
|
|
469
|
+
return os.environ.get("TOKENSAFE_OUMV_EDIT_NUDGE", "").strip().lower() not in ("0", "false", "no", "off")
|
|
470
|
+
|
|
462
471
|
|
|
463
472
|
def _gc_oumv_markers(data_dir: str) -> None:
|
|
464
473
|
"""Drops one-shot OUMV markers older than a week: one accrues per session forever."""
|
|
@@ -680,9 +689,19 @@ def evaluate_cc_pre_tool_use(payload: Dict[str, Any], agent: str) -> Dict[str, A
|
|
|
680
689
|
)
|
|
681
690
|
except Exception:
|
|
682
691
|
pass
|
|
683
|
-
#
|
|
684
|
-
#
|
|
685
|
-
#
|
|
692
|
+
# Advisory only, and only for hosts whose PreToolUse schema documents
|
|
693
|
+
# additionalContext (Claude Code): omitting permissionDecision keeps the
|
|
694
|
+
# normal permission flow, while returning "allow" used to auto-approve edits.
|
|
695
|
+
# Kill switch: TOKENSAFE_OUMV_EDIT_NUDGE=0.
|
|
696
|
+
if agent in _OUMV_EDIT_NUDGE_AGENTS and _oumv_edit_nudge_enabled():
|
|
697
|
+
note = get_oumv_read_edit_advisory(cwd, file_path, session_id)
|
|
698
|
+
if note:
|
|
699
|
+
return {
|
|
700
|
+
"hookSpecificOutput": {
|
|
701
|
+
"hookEventName": "PreToolUse",
|
|
702
|
+
"additionalContext": note,
|
|
703
|
+
}
|
|
704
|
+
}
|
|
686
705
|
return {}
|
|
687
706
|
|
|
688
707
|
if canon == "read":
|