tokensafe 4.5.0 → 4.5.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.
- package/.codex-plugin/plugin.json +1 -1
- package/bin/agy-tokens +10 -1
- package/bin/tokensafe.js +2 -1
- package/hooks/claude_code_hook.py +38 -126
- package/hooks/cursor_hook.py +45 -1
- package/hooks/kimi_hook.py +46 -90
- package/hooks/pre_invocation.py +23 -4
- package/hooks/pre_tool_use.py +40 -22
- package/hooks/session_start.py +28 -10
- package/hooks/zcode_hook.py +95 -0
- package/hooks.json +1 -1
- package/kimi.plugin.json +17 -1
- package/mcp_config.json +10 -4
- package/package.json +1 -1
- package/plugin.json +1 -1
- package/rules/AGENTS.md +24 -24
- package/server.json +3 -3
- package/skills/token-optimizer/SKILL.md +61 -86
- package/skills/token-optimizer/references/mcp-tools.md +32 -132
- package/src/adapter_core.py +231 -7
- package/src/batch_editor.py +73 -22
- package/src/batch_search.py +31 -11
- package/src/burn_monitor.py +581 -0
- package/src/cache_normalizer.py +2 -0
- package/src/cli.py +34 -4
- package/src/compactor.py +1 -1
- package/src/dashboard.py +17 -9
- package/src/diff_slicer.py +1 -1
- package/src/distiller.py +11 -1
- package/src/environment_auditor.py +30 -6
- package/src/format_parsers/ansi.py +1 -1
- package/src/format_parsers/lockfiles.py +22 -17
- package/src/format_parsers/tabular.py +6 -3
- package/src/fts_index.py +26 -20
- package/src/governor.py +2 -2
- package/src/graph_engine.py +31 -9
- package/src/guard.py +3 -3
- package/src/image_downscale.py +26 -0
- package/src/installer.py +61 -48
- package/src/license_manager.py +49 -16
- package/src/live_relay.py +9 -8
- package/src/mcp_server.py +487 -48
- package/src/metrics.py +10 -1
- package/src/mistakes.py +4 -2
- package/src/paths.py +4 -1
- package/src/proxy.py +302 -123
- package/src/result_ledger.py +39 -1
- package/src/schema_slicer.py +40 -18
- package/src/scoped_search.py +66 -23
- package/src/skeletonizer.py +22 -11
- package/src/slicer.py +6 -4
- package/src/stash.py +37 -7
- package/src/superseded.py +42 -23
- package/src/syntax_guard.py +2 -0
- package/src/team_cache.py +3 -0
- package/src/telemetry_sync.py +66 -53
- package/src/thinking_fold.py +50 -12
- package/src/transcript_analyzer.py +270 -68
- package/src/treesitter_backend.py +2 -0
- package/src/type_slicer.py +60 -18
- package/src/version_checker.py +1 -1
- package/src/web_reader.py +55 -22
package/hooks/pre_tool_use.py
CHANGED
|
@@ -41,6 +41,13 @@ def _resolve_hook_path(raw_path: str, hook_cwd: str) -> str:
|
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
def _handle(payload: dict) -> dict:
|
|
44
|
+
# If invoked by ZCode / Claude Code (tool_name + tool_input without Antigravity toolCall),
|
|
45
|
+
# route through the CC/ZCode PreToolUse evaluator so we return {} / hookSpecificOutput
|
|
46
|
+
# instead of {"decision": "allow"} (which causes hook.run.failed in ZCode).
|
|
47
|
+
if not isinstance(payload.get("toolCall"), dict) and payload.get("tool_name"):
|
|
48
|
+
from src.adapter_core import evaluate_cc_pre_tool_use
|
|
49
|
+
return evaluate_cc_pre_tool_use(payload, agent=str(payload.get("agent") or "zcode"))
|
|
50
|
+
|
|
44
51
|
tool_call = payload.get("toolCall")
|
|
45
52
|
if not isinstance(tool_call, dict):
|
|
46
53
|
tool_call = {}
|
|
@@ -48,18 +55,24 @@ def _handle(payload: dict) -> dict:
|
|
|
48
55
|
args = tool_call.get("args")
|
|
49
56
|
if not isinstance(args, dict):
|
|
50
57
|
args = {}
|
|
58
|
+
from src.adapter_core import canonical_tool_name
|
|
59
|
+
canon_tool = canonical_tool_name(tool_name)
|
|
51
60
|
conversation_id = str(payload.get("conversationId") or "default_session")
|
|
52
61
|
last_user_input = str(payload.get("lastUserInput") or "")
|
|
53
62
|
# Working directory of the tool call: lets CommandSanitizer peek at
|
|
54
63
|
# package.json and Guard audit git staging in the user's repo (never plugin CWD).
|
|
55
|
-
workspace_paths = payload
|
|
56
|
-
|
|
64
|
+
workspace_paths = [str(w) for w in payload["workspacePaths"] if str(w).strip()] if isinstance(payload.get("workspacePaths"), list) else []
|
|
65
|
+
explicit_cwd = str(payload.get("cwd") or "").strip()
|
|
66
|
+
hook_cwd = explicit_cwd or (workspace_paths[0] if workspace_paths else "") or os.getcwd()
|
|
57
67
|
try:
|
|
58
68
|
from src.paths import save_active_workspace
|
|
59
|
-
if workspace_paths
|
|
60
|
-
save_active_workspace(
|
|
61
|
-
elif
|
|
62
|
-
|
|
69
|
+
if workspace_paths:
|
|
70
|
+
save_active_workspace(workspace_paths[0])
|
|
71
|
+
elif explicit_cwd and any(
|
|
72
|
+
os.path.exists(os.path.join(explicit_cwd, m))
|
|
73
|
+
for m in (".git", "package.json", "pyproject.toml", "go.mod", "Cargo.toml", "requirements.txt")
|
|
74
|
+
):
|
|
75
|
+
save_active_workspace(explicit_cwd)
|
|
63
76
|
except Exception:
|
|
64
77
|
pass
|
|
65
78
|
|
|
@@ -92,11 +105,11 @@ def _handle(payload: dict) -> dict:
|
|
|
92
105
|
# either corrupts content or fails and forces a costly full re-read.
|
|
93
106
|
# Surface it BEFORE the edit lands — force_ask, never deny.
|
|
94
107
|
# Kill switch: TOKENSAFE_STALE_GUARD=0.
|
|
95
|
-
if
|
|
108
|
+
if canon_tool == "edit":
|
|
96
109
|
try:
|
|
97
110
|
from src.file_state import FileState
|
|
98
111
|
if FileState.guard_enabled():
|
|
99
|
-
raw_path = str(args.get("Path") or args.get("TargetFile") or args.get("path") or "")
|
|
112
|
+
raw_path = str(args.get("Path") or args.get("TargetFile") or args.get("path") or args.get("file_path") or "")
|
|
100
113
|
stale = FileState.check_stale(_resolve_hook_path(raw_path, hook_cwd)) if raw_path else None
|
|
101
114
|
if stale:
|
|
102
115
|
tracker.record_event(
|
|
@@ -124,11 +137,16 @@ def _handle(payload: dict) -> dict:
|
|
|
124
137
|
pass
|
|
125
138
|
|
|
126
139
|
# 2. TokenSafe Guard: Inspect file writes and edits for security violations
|
|
127
|
-
if
|
|
140
|
+
if canon_tool in ("write", "edit"):
|
|
128
141
|
from src.guard import TokenSafeGuard
|
|
129
|
-
|
|
142
|
+
from src.adapter_core import extract_write_content
|
|
143
|
+
raw_path = str(args.get("Path") or args.get("TargetFile") or args.get("path") or args.get("file_path") or "")
|
|
130
144
|
path = _resolve_hook_path(raw_path, hook_cwd)
|
|
131
|
-
code_to_check =
|
|
145
|
+
code_to_check = (
|
|
146
|
+
(args.get("Content") or args.get("content") or "")
|
|
147
|
+
if canon_tool == "write"
|
|
148
|
+
else (extract_write_content(tool_name, args) or "")
|
|
149
|
+
)
|
|
132
150
|
guard_res = TokenSafeGuard.inspect_file_write(path, code_to_check)
|
|
133
151
|
if guard_res.blocked:
|
|
134
152
|
tracker.record_event(
|
|
@@ -158,23 +176,22 @@ def _handle(payload: dict) -> dict:
|
|
|
158
176
|
|
|
159
177
|
# 3. Output Guard (shared guard_write, v3.0.0): deny wholesale overwrite of
|
|
160
178
|
# large existing files to enforce edit_file; ask on small-delta writes.
|
|
161
|
-
if
|
|
162
|
-
raw_path = str(args.get("Path") or args.get("path") or "")
|
|
179
|
+
if canon_tool == "write":
|
|
180
|
+
raw_path = str(args.get("Path") or args.get("path") or args.get("file_path") or "")
|
|
163
181
|
path = _resolve_hook_path(raw_path, hook_cwd)
|
|
164
|
-
content = args.get("Content"
|
|
165
|
-
is_append = args.get("Append", False)
|
|
182
|
+
content = args.get("Content") or args.get("content") or ""
|
|
183
|
+
is_append = args.get("Append", args.get("append", False))
|
|
166
184
|
verdict = guard_write(path, str(content or ""), bool(is_append), "antigravity", conversation_id)
|
|
167
185
|
if verdict["decision"] in ("deny", "ask"):
|
|
168
186
|
_trigger_bg_sync()
|
|
169
187
|
return {"decision": verdict["decision"], "reason": verdict["reason"]}
|
|
170
188
|
|
|
171
189
|
# 3. read_file Optimization (AST Windowing & Skeletonization).
|
|
172
|
-
# 'view_file'
|
|
173
|
-
|
|
174
|
-
elif tool_name in ("read_file", "view_file"):
|
|
190
|
+
# 'view_file' and 'Read' route through the same optimization pipeline.
|
|
191
|
+
elif canon_tool == "read":
|
|
175
192
|
from src.slicer import ToolSlicer
|
|
176
193
|
from src.skeletonizer import Skeletonizer
|
|
177
|
-
raw_path = str(args.get("Path") or args.get("path") or args.get("FilePath") or "")
|
|
194
|
+
raw_path = str(args.get("Path") or args.get("path") or args.get("FilePath") or args.get("file_path") or "")
|
|
178
195
|
path = _resolve_hook_path(raw_path, hook_cwd)
|
|
179
196
|
start_line = args.get("StartLine")
|
|
180
197
|
if start_line is None:
|
|
@@ -325,11 +342,11 @@ def _handle(payload: dict) -> dict:
|
|
|
325
342
|
return response
|
|
326
343
|
|
|
327
344
|
# 4. run_command Optimization & TokenSafe Guard
|
|
328
|
-
elif
|
|
345
|
+
elif canon_tool == "bash":
|
|
329
346
|
from src.guard import TokenSafeGuard
|
|
330
347
|
from src.diff_slicer import DiffSlicer
|
|
331
348
|
from src.command_sanitizer import CommandSanitizer
|
|
332
|
-
cmd = str(args.get("CommandLine") or "")
|
|
349
|
+
cmd = str(args.get("CommandLine") or args.get("command") or "")
|
|
333
350
|
guard_res = TokenSafeGuard.inspect_command(cmd, cwd=hook_cwd)
|
|
334
351
|
if guard_res.blocked:
|
|
335
352
|
tracker.record_event(
|
|
@@ -376,7 +393,8 @@ def _handle(payload: dict) -> dict:
|
|
|
376
393
|
new_cmd, est_saved, reason = diff_cmd, diff_saved, diff_reason
|
|
377
394
|
|
|
378
395
|
if new_cmd and est_saved > 0:
|
|
379
|
-
|
|
396
|
+
cmd_key = "command" if "command" in args and "CommandLine" not in args else "CommandLine"
|
|
397
|
+
response["overwrite"] = {cmd_key: new_cmd}
|
|
380
398
|
response["reason"] = f"Token Optimizer: {reason} (Saved ~{est_saved} tokens)"
|
|
381
399
|
|
|
382
400
|
tracker.record_event(
|
package/hooks/session_start.py
CHANGED
|
@@ -85,12 +85,13 @@ def main():
|
|
|
85
85
|
# hooks.md: hook CWD is the plugin directory, not the workspace — use the
|
|
86
86
|
# workspacePaths from the payload for project-scoped audits.
|
|
87
87
|
raw_ws = payload.get("workspacePaths")
|
|
88
|
-
workspace_paths = raw_ws if isinstance(raw_ws, list) else []
|
|
89
|
-
workspace_root =
|
|
88
|
+
workspace_paths = [str(w) for w in raw_ws if str(w).strip()] if isinstance(raw_ws, list) else []
|
|
89
|
+
workspace_root = workspace_paths[0] if workspace_paths else os.getcwd()
|
|
90
90
|
try:
|
|
91
91
|
from src.paths import save_active_workspace, ensure_tokensafe_gitignore
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
if workspace_paths:
|
|
93
|
+
save_active_workspace(workspace_root)
|
|
94
|
+
ensure_tokensafe_gitignore(workspace_root)
|
|
94
95
|
except Exception:
|
|
95
96
|
pass
|
|
96
97
|
|
|
@@ -111,7 +112,7 @@ def main():
|
|
|
111
112
|
f"{directives}\n\n"
|
|
112
113
|
f"{banner}\n"
|
|
113
114
|
"⚡ Core God Nodes and dependency hubs mapped above. "
|
|
114
|
-
"Call 'tokensafe:
|
|
115
|
+
"Call 'tokensafe:repo_map(view=\"graph\", project_path=...)' for full dependency trees."
|
|
115
116
|
)
|
|
116
117
|
except Exception:
|
|
117
118
|
pass
|
|
@@ -135,6 +136,14 @@ def main():
|
|
|
135
136
|
except Exception:
|
|
136
137
|
pass
|
|
137
138
|
|
|
139
|
+
try:
|
|
140
|
+
from src.adapter_core import format_cumulative_banner
|
|
141
|
+
cum_banner = format_cumulative_banner()
|
|
142
|
+
if cum_banner:
|
|
143
|
+
system_sections.append(cum_banner)
|
|
144
|
+
except Exception:
|
|
145
|
+
pass
|
|
146
|
+
|
|
138
147
|
inject_steps = [
|
|
139
148
|
{"systemMessage": {"systemMessage": "\n\n".join(system_sections), "metadata": {}}}
|
|
140
149
|
]
|
|
@@ -156,11 +165,8 @@ def main():
|
|
|
156
165
|
except Exception:
|
|
157
166
|
pass
|
|
158
167
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
threading.Thread(target=LicenseManager.ensure_community_license, daemon=True).start()
|
|
162
|
-
except Exception:
|
|
163
|
-
pass
|
|
168
|
+
# Variant A: Anonymous installs stay on 50k Guest mode until `tokensafe login`
|
|
169
|
+
# unlocks the 500k Community license (never auto-issue 500k in SessionStart).
|
|
164
170
|
|
|
165
171
|
try:
|
|
166
172
|
bloat_warning = EnvironmentAuditor.get_bloat_warning(workspace_root=workspace_root)
|
|
@@ -169,6 +175,18 @@ def main():
|
|
|
169
175
|
except Exception:
|
|
170
176
|
pass
|
|
171
177
|
|
|
178
|
+
try:
|
|
179
|
+
from src.burn_monitor import get_burn_warnings
|
|
180
|
+
burn_warn = get_burn_warnings(
|
|
181
|
+
agent="antigravity",
|
|
182
|
+
session_id=str(payload.get("conversationId") or ""),
|
|
183
|
+
transcript_path=str(payload.get("transcriptPath") or ""),
|
|
184
|
+
)
|
|
185
|
+
if burn_warn:
|
|
186
|
+
inject_steps.append(_user_markdown(burn_warn))
|
|
187
|
+
except Exception:
|
|
188
|
+
pass
|
|
189
|
+
|
|
172
190
|
print(json.dumps({"injectSteps": inject_steps}))
|
|
173
191
|
|
|
174
192
|
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""
|
|
3
|
+
TokenSafe adapter for ZCode (Z.ai Code) lifecycle hooks (~/.zcode/cli/config.json).
|
|
4
|
+
|
|
5
|
+
Speaks the ZCode / Claude Code JSON hook contract:
|
|
6
|
+
SessionStart -> injects TokenSafe directives, God Nodes banner, and burn alerts.
|
|
7
|
+
UserPromptSubmit -> compacts prompt (TOCP) + emits live burn warnings from model-io-*.jsonl.
|
|
8
|
+
PreToolUse -> LoopDetector, MistakesLedger, Bash/Write/Edit/Read guards, stale-edit check.
|
|
9
|
+
PostToolUse -> compacts verbose shell output, records FileState + command failures.
|
|
10
|
+
Stop -> flushes telemetry and runs optional fold-at-rest.
|
|
11
|
+
|
|
12
|
+
Contract: stdin = one JSON payload, stdout = one JSON response ({} on clean allow).
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
import json
|
|
16
|
+
import os
|
|
17
|
+
import sys
|
|
18
|
+
|
|
19
|
+
HOOK_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
20
|
+
PROJECT_ROOT = os.path.dirname(HOOK_DIR)
|
|
21
|
+
if PROJECT_ROOT not in sys.path:
|
|
22
|
+
sys.path.insert(0, PROJECT_ROOT)
|
|
23
|
+
|
|
24
|
+
from hooks.claude_code_hook import handle as _cc_handle # noqa: E402
|
|
25
|
+
|
|
26
|
+
AGENT = "zcode"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def handle(event: str, payload: dict) -> dict:
|
|
30
|
+
# Normalize ZCode-specific camelCase aliases onto CC fields while preserving existing keys.
|
|
31
|
+
norm = dict(payload)
|
|
32
|
+
if not norm.get("session_id") and norm.get("conversationId"):
|
|
33
|
+
norm["session_id"] = norm["conversationId"]
|
|
34
|
+
if not norm.get("prompt") and norm.get("lastUserInput"):
|
|
35
|
+
norm["prompt"] = norm["lastUserInput"]
|
|
36
|
+
if not norm.get("transcript_path") and norm.get("transcriptPath"):
|
|
37
|
+
norm["transcript_path"] = norm["transcriptPath"]
|
|
38
|
+
if not norm.get("tool_name") and isinstance(norm.get("toolCall"), dict):
|
|
39
|
+
tc = norm["toolCall"]
|
|
40
|
+
norm["tool_name"] = tc.get("name") or ""
|
|
41
|
+
if not norm.get("tool_input"):
|
|
42
|
+
raw_in = tc.get("args") if tc.get("args") is not None else (tc.get("input") if tc.get("input") is not None else tc.get("arguments"))
|
|
43
|
+
if isinstance(raw_in, dict):
|
|
44
|
+
norm["tool_input"] = raw_in
|
|
45
|
+
elif isinstance(raw_in, str) and raw_in.strip():
|
|
46
|
+
try:
|
|
47
|
+
parsed_in = json.loads(raw_in)
|
|
48
|
+
if isinstance(parsed_in, dict):
|
|
49
|
+
norm["tool_input"] = parsed_in
|
|
50
|
+
except Exception:
|
|
51
|
+
pass
|
|
52
|
+
if "tool_response" not in norm and "toolResponse" in norm:
|
|
53
|
+
norm["tool_response"] = norm["toolResponse"]
|
|
54
|
+
if not norm.get("cwd") and isinstance(norm.get("workspacePaths"), list) and norm["workspacePaths"]:
|
|
55
|
+
norm["cwd"] = str(norm["workspacePaths"][0])
|
|
56
|
+
return _cc_handle(event, norm, agent=AGENT)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def main():
|
|
60
|
+
try:
|
|
61
|
+
raw = sys.stdin.read()
|
|
62
|
+
payload = json.loads(raw) if raw.strip() else {}
|
|
63
|
+
if not isinstance(payload, dict):
|
|
64
|
+
payload = {}
|
|
65
|
+
except Exception:
|
|
66
|
+
print(json.dumps({}))
|
|
67
|
+
return
|
|
68
|
+
event = ""
|
|
69
|
+
try:
|
|
70
|
+
event = str(payload.get("hook_event_name") or payload.get("hookEventName") or "")
|
|
71
|
+
if not event:
|
|
72
|
+
if "tool_name" in payload or "toolCall" in payload:
|
|
73
|
+
event = "PostToolUse" if ("tool_response" in payload or "toolResponse" in payload) else "PreToolUse"
|
|
74
|
+
elif "prompt" in payload or "lastUserInput" in payload:
|
|
75
|
+
event = "UserPromptSubmit"
|
|
76
|
+
elif "terminationReason" in payload or "fullyIdle" in payload:
|
|
77
|
+
event = "Stop"
|
|
78
|
+
else:
|
|
79
|
+
event = "SessionStart"
|
|
80
|
+
response = handle(event, payload)
|
|
81
|
+
if not isinstance(response, dict):
|
|
82
|
+
response = {}
|
|
83
|
+
except Exception:
|
|
84
|
+
response = {}
|
|
85
|
+
if event in ("UserPromptSubmit", "PreToolUse", "PostToolUse", "Stop"):
|
|
86
|
+
try:
|
|
87
|
+
from src.telemetry_sync import TelemetrySync
|
|
88
|
+
TelemetrySync.sync_background(throttle_seconds=0.0 if event == "Stop" else 20.0)
|
|
89
|
+
except Exception:
|
|
90
|
+
pass
|
|
91
|
+
print(json.dumps(response))
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
if __name__ == "__main__":
|
|
95
|
+
main()
|
package/hooks.json
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
],
|
|
25
25
|
"PreToolUse": [
|
|
26
26
|
{
|
|
27
|
-
"matcher": "read_file|view_file|run_command|write_file|edit_file",
|
|
27
|
+
"matcher": "read_file|view_file|run_command|write_file|edit_file|replace_file_content|multi_replace_file_content|find_by_name|grep_search|list_dir",
|
|
28
28
|
"hooks": [
|
|
29
29
|
{
|
|
30
30
|
"type": "command",
|
package/kimi.plugin.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
|
-
"version": "4.5.
|
|
3
|
+
"version": "4.5.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": "MIT",
|
|
@@ -52,11 +52,27 @@
|
|
|
52
52
|
"command": "python3 hooks/kimi_hook.py",
|
|
53
53
|
"timeout": 10
|
|
54
54
|
},
|
|
55
|
+
{
|
|
56
|
+
"event": "PreToolUse",
|
|
57
|
+
"matcher": "Edit",
|
|
58
|
+
"command": "python3 hooks/kimi_hook.py",
|
|
59
|
+
"timeout": 10
|
|
60
|
+
},
|
|
55
61
|
{
|
|
56
62
|
"event": "PreToolUse",
|
|
57
63
|
"matcher": "Read",
|
|
58
64
|
"command": "python3 hooks/kimi_hook.py",
|
|
59
65
|
"timeout": 10
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
"event": "PostToolUse",
|
|
69
|
+
"command": "python3 hooks/kimi_hook.py",
|
|
70
|
+
"timeout": 10
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"event": "Stop",
|
|
74
|
+
"command": "python3 hooks/kimi_hook.py",
|
|
75
|
+
"timeout": 15
|
|
60
76
|
}
|
|
61
77
|
]
|
|
62
78
|
}
|
package/mcp_config.json
CHANGED
|
@@ -7,19 +7,25 @@
|
|
|
7
7
|
"exec \"${TOKENSAFE_PYTHON:-python3}\" \"$PLUGIN_ROOT/src/mcp_server.py\""
|
|
8
8
|
],
|
|
9
9
|
"tools": {
|
|
10
|
+
"smart_read_file": {
|
|
11
|
+
"eager": true
|
|
12
|
+
},
|
|
13
|
+
"scoped_search": {
|
|
14
|
+
"eager": true
|
|
15
|
+
},
|
|
10
16
|
"apply_edits": {
|
|
11
17
|
"eager": true
|
|
12
18
|
},
|
|
13
|
-
"
|
|
19
|
+
"repo_map": {
|
|
14
20
|
"eager": true
|
|
15
21
|
},
|
|
16
|
-
"
|
|
22
|
+
"session_context": {
|
|
17
23
|
"eager": true
|
|
18
24
|
},
|
|
19
|
-
"
|
|
25
|
+
"oumv": {
|
|
20
26
|
"eager": true
|
|
21
27
|
},
|
|
22
|
-
"
|
|
28
|
+
"run_helper": {
|
|
23
29
|
"eager": true
|
|
24
30
|
}
|
|
25
31
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tokensafe",
|
|
3
3
|
"mcpName": "dev.tokensafe/tokensafe",
|
|
4
|
-
"version": "4.5.
|
|
4
|
+
"version": "4.5.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.5.
|
|
4
|
+
"version": "4.5.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
|
"logo": "assets/logo.png",
|
|
7
7
|
"developerName": "TokenSafe",
|
package/rules/AGENTS.md
CHANGED
|
@@ -21,32 +21,32 @@ Execute the specified action directly based on these extracted parameters.
|
|
|
21
21
|
|
|
22
22
|
### 2. Zero-Fluff Output Directives (Egress Optimization)
|
|
23
23
|
1. **No Conversational Filler**: Never include courtesy greetings or sign-offs (e.g., "Certainly!", "Sure, I can help", "Let me know if you need anything else").
|
|
24
|
-
2. **Surgical Code Edits, Batching & Zero In-Place Stream Editing**: Prefer `
|
|
24
|
+
2. **Surgical Code Edits, Batching & Zero In-Place Stream Editing**: Prefer `tokensafe:apply_edits(edits=[...], verify="npm test")` for >=2 hunks/files or edit + verify loops. For single tweaks, use `edit_file` with exact `Target` and `Replacement`. NEVER run terminal stream editors (`sed -i`, `perl -i`, `awk -i`) on source code (hard-blocked by TokenSafe Guard), and never suppress errors (`2>/dev/null`).
|
|
25
25
|
3. **Diff-Centric Responses**: Never reprint entire unmodified files or long boilerplate blocks. Reference file lines instead (e.g., `wallet.ts#L42-L50`).
|
|
26
26
|
4. **Dense Formatting**: Use compact bullet points and direct technical prose.
|
|
27
|
-
5. **Repeat Read Deduplication**: Never re-read unchanged files or symbols in the same session. Reuse the skeleton or pointer reference (`// [TokenSafe: Pointer Hit ...]`) returned earlier;
|
|
28
|
-
6. **Compact Test Output Execution**: Run unit tests
|
|
29
|
-
7. **Multimodal Image Isolation (Prompt Cache Protection)**:
|
|
30
|
-
8. **Startup Snapshot Utilization**:
|
|
31
|
-
9. **Zero-Spill 8.8 KB Cap & Reversible Stash**: All TokenSafe MCP outputs are
|
|
32
|
-
|
|
33
|
-
### 3. Architecture & Code Navigation Directives (
|
|
34
|
-
1. **
|
|
35
|
-
2. **
|
|
36
|
-
3. **
|
|
37
|
-
4. **
|
|
38
|
-
5. **
|
|
39
|
-
6. **
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
27
|
+
5. **Repeat Read Deduplication**: Never re-read unchanged files or symbols in the same session. Reuse the skeleton or pointer reference (`// [TokenSafe: Pointer Hit ...]`) returned earlier; pass `force_full=true` only after compaction or as a fresh subagent.
|
|
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
|
+
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
|
+
8. **Startup Snapshot Utilization**: Check `[TokenSafe Workspace Snapshot]` on turn 1 before running exploratory `ls` or `git status`.
|
|
31
|
+
9. **Zero-Spill 8.8 KB Cap & Reversible Stash**: All TokenSafe MCP outputs are capped at <= 8.8 KB with `[TokenSafe folded: #hash ...]` anchors. Call `tokensafe:run_helper(action="expand", hash="...")` if full raw content is needed.
|
|
32
|
+
|
|
33
|
+
### 3. Architecture & Code Navigation Directives (7 Consolidated MCP Tools)
|
|
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.
|
|
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
|
+
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.
|
|
39
|
+
6. **Utilities (`run_helper`)**: Call `tokensafe:run_helper(action=...)` for:
|
|
40
|
+
- `"expand"` (`hash`): restore stashed `#hash` content
|
|
41
|
+
- `"web"` (`url`): fetch clean Markdown docs (-80-95% tokens, L1/L2/L3 cached)
|
|
42
|
+
- `"deps"` (`package_name`, `lockfile_path`): point lockfile lookup in <50 tokens
|
|
43
|
+
- `"sanitize"` (`command`, `cwd`): rewrite noisy shell/test commands
|
|
44
|
+
- `"guard"` (`command`/`code`, `file_path`): pre-flight security/hygiene audit
|
|
45
|
+
- `"diff"` (`diff`): slice unified git diffs
|
|
46
|
+
- `"image"` (`image_path`, `max_edge=1024`): downscale screenshots (-50-75% vision tokens)
|
|
47
|
+
- `"compress"` (`prompt`): TOCP S-expression compression
|
|
48
|
+
7. **Universal OUMV Protocol (`oumv`)**: For live Frontend (ports 5173/3000) and Backend (ports 8080/8000) runtimes, call `tokensafe:oumv(action="status"|"observe"|"understand"|"verify"|"mutate"|"graph", ...)` instead of headless browsers or blind shell curls.
|
|
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)
|
|
52
52
|
At the end of your response for any turn where tools were executed, files were inspected, commands were sanitized, or prompts were compacted, append a compact 1-line footer:
|
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.5.
|
|
6
|
+
"version": "4.5.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.5.
|
|
26
|
+
"version": "4.5.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.5.
|
|
42
|
+
"version": "4.5.1",
|
|
43
43
|
"runtimeHint": "uvx",
|
|
44
44
|
"transport": {
|
|
45
45
|
"type": "stdio"
|