tokensafe 4.2.4 → 4.2.5

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,7 +1,7 @@
1
1
  {
2
- "version": "4.2.4",
2
+ "version": "4.2.5",
3
3
  "name": "tokensafe",
4
- "description": "Your coding agent isn't getting dumber. Your context is just full of trash. Local context firewall & zero-loss runtime for Cursor, Claude Code, and autonomous agents.",
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": {
6
6
  "name": "TokenSafe",
7
7
  "url": "https://tokensafe.dev"
package/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
  <!-- mcp-name: dev.tokensafe/tokensafe -->
7
7
 
8
8
  <p align="center">
9
- <b>Your coding agent isn't getting dumber. Your context is just full of trash.</b><br>
10
- When chat sessions fill up with massive lockfiles and endless build logs, your AI loses focus.<br>
11
- TokenSafe strips the noise with Tree-sitter AST slicing so your agent stays razor-sharp, changes only the lines you asked for, and never leaks your secrets.<br>
9
+ <b>Your AI agent is smart enough to code all day. Now it actually can.</b><br>
10
+ Stop letting bloated file reads, noisy test dumps, and broken prompt caches drain your limits by lunch.<br>
11
+ TokenSafe runs locally, filtering context down to what the model actually touches while keeping secrets out of git.<br>
12
12
  Works with <b>Cursor, Claude Code, Codex, Windsurf, Google Antigravity, Kimi Code, and ChatGPT</b>.
13
13
  </p>
14
14
 
package/kimi.plugin.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tokensafe",
3
- "version": "4.2.4",
4
- "description": "Your coding agent isn't getting dumber. Your context is just full of trash. Local context firewall & zero-loss runtime for Cursor, Claude Code, and autonomous agents.",
3
+ "version": "4.2.5",
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",
7
7
  "logo": "https://tokensafe.dev/logo.png",
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "tokensafe",
3
3
  "mcpName": "dev.tokensafe/tokensafe",
4
- "version": "4.2.4",
5
- "description": "Your coding agent isn't getting dumber. Your context is just full of trash. Local context firewall & zero-loss runtime for Cursor, Claude Code, and autonomous agents.",
4
+ "version": "4.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": {
8
8
  "tokensafe": "bin/tokensafe.js"
package/plugin.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "tokensafe",
3
3
  "displayName": "TokenSafe",
4
- "version": "4.2.4",
5
- "description": "Your coding agent isn't getting dumber. Your context is just full of trash. Local context firewall & zero-loss runtime for Cursor, Claude Code, and autonomous agents.",
4
+ "version": "4.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": "https://tokensafe.dev/logo.png",
7
7
  "developerName": "TokenSafe",
8
8
  "author": {
package/rules/AGENTS.md CHANGED
@@ -21,7 +21,7 @@ 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**: Prefer `edit_file` with concise `Target` and `Replacement` over `write_file` on large existing files.
24
+ 2. **Surgical Code Edits & Zero In-Place Stream Editing**: Prefer `edit_file` with concise `Target` and `Replacement` over `write_file` on large existing files. NEVER run terminal stream editors (`sed -i`, `perl -i`, `awk -i`) to edit or delete source code — blind numeric ranges cause line-drift and silent code loss (hard-blocked by TokenSafe Guard). NEVER suppress errors (`2>/dev/null`) on file modifications.
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
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; only pass `force_full=true` if your context was compacted or you are a fresh subagent.
package/server.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
3
3
  "name": "dev.tokensafe/tokensafe",
4
4
  "title": "TokenSafe",
5
- "description": "Your agent isn't getting dumber, your context is full of trash. Local firewall & zero-loss runtime.",
6
- "version": "4.2.4",
5
+ "description": "Your AI agent is smart enough to code all day. Now it actually can. Local firewall & zero-loss runtime.",
6
+ "version": "4.2.5",
7
7
  "websiteUrl": "https://tokensafe.dev",
8
8
  "repository": {
9
9
  "url": "https://github.com/tokensafe-dev/tokensafe",
@@ -30,7 +30,7 @@
30
30
  "registryType": "npm",
31
31
  "registryBaseUrl": "https://registry.npmjs.org",
32
32
  "identifier": "tokensafe",
33
- "version": "4.2.4",
33
+ "version": "4.2.5",
34
34
  "runtimeHint": "npx",
35
35
  "transport": {
36
36
  "type": "stdio"
@@ -46,7 +46,7 @@
46
46
  "registryType": "pypi",
47
47
  "registryBaseUrl": "https://pypi.org",
48
48
  "identifier": "tokensafe",
49
- "version": "4.2.4",
49
+ "version": "4.2.5",
50
50
  "runtimeHint": "uvx",
51
51
  "transport": {
52
52
  "type": "stdio"
@@ -42,8 +42,10 @@ folds multi-turn conversation history, slices verbose tool outputs, and guards a
42
42
  - NEVER run `ls -la` or `ls -l` in terminal.
43
43
  - Call `tokensafe:list_dir(path=".", depth=2)` for clean directory trees without permissions, timestamps, or lockfiles (-90% tokens). Supports relative subfolders (`path="src"`).
44
44
 
45
- 6. **SURGICAL FILE EDITS (`edit_file`)**:
45
+ 6. **SURGICAL FILE EDITS (`edit_file`) & IN-PLACE STREAM MUTATION GUARD (`sed -i` HARD-BLOCKED)**:
46
46
  - On existing files with >= 40 lines, wholesale rewrites via `write_file` are blocked by **Output Guard**. Always use `edit_file` with precise `Target` and `Replacement` blocks.
47
+ - Strictly NEVER run `sed -i`, `perl -i`, `awk -i`, or terminal stream editors on source files (`.ts`, `.tsx`, `.py`, `.js`, etc.) or with numeric line ranges (`'10,20d'`). Blind numeric editing causes line-drift and catastrophic accidental code deletion. These commands are hard-blocked by **TokenSafe Guard** (`decision: deny`).
48
+ - NEVER suppress errors with `2>/dev/null` or `&>/dev/null` on file modifications or build commands; failures must fail fast and loud.
47
49
 
48
50
  7. **SECRET LEAK PREVENTION (ZERO HARDCODED FALLBACKS)**:
49
51
  - Never provide real private keys, API secrets, or credentials as fallback values in `os.environ.get()` or `process.env`. Real credentials must exist strictly in environment variables.
@@ -10,6 +10,7 @@ TokenSafe Guard automatically intercepts dangerous operations in `PreToolUse`:
10
10
  | **SQL_INJECTION** | Unsafe f-string / template string interpolation in queries | **Blocked** (`decision: deny`), enforces parameterized queries |
11
11
  | **GIT_SECRET_STAGING** | `git add .env` or blanket staging with unignored secrets | **Blocked** (`decision: deny`), prevents staging credentials |
12
12
  | **DESTRUCTIVE_RM** | `rm -rf /`, `rm -rf ~`, `rm -rf *` | **Blocked** (`decision: deny`), prevents catastrophic deletion |
13
+ | **INPLACE_STREAM_EDIT** | `sed -i`, `perl -i`, `awk -i` on source code or with numeric line ranges (`'10,20d'`) | **Blocked** (`decision: deny`), prevents line-drift and code loss; directs to `edit_file` |
13
14
  | **DATA_EXFILTRATION** | Piping `.env` or private keys to `curl`/`wget` | **Blocked** (`decision: deny`), prevents secret leakage |
14
15
  | **PACKAGE_TYPOSQUAT** | Installing known typosquatted packages | **Warning** injected into turn context |
15
16
  | **INFINITE_STREAM** (adapters) | Never-terminating commands: `tail -f`, `watch`, `docker attach`, `docker/kubectl logs -f`, `vitest` (watch by default — use `vitest run`), `jest`/`vitest --watch` | **Asked** (`decision: ask`) — intentional runs proceed via confirmation |
@@ -42,6 +42,7 @@ TOKENSAFE_DIRECTIVES = (
42
42
  "• To inspect all exported types/interfaces: call 'tokensafe:get_api_surface(project_path)'.\n"
43
43
  "• Before large multi-step tasks: call 'tokensafe:context_budget(model=...)' to check context headroom and Quality Score (Grade S-F).\n"
44
44
  "• When context_budget reports warning/critical or Grade C/F: call 'tokensafe:compact_conversation(transcript_path=...)' to fold history before continuing.\n"
45
+ "• 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"
45
46
  "• Prefer 'edit_file' over 'write_file' for existing files."
46
47
  )
47
48
 
package/src/guard.py CHANGED
@@ -9,6 +9,7 @@ Protects local workspaces and repository integrity by intercepting dangerous ope
9
9
  6. Destructive Shell Command & Unbounded Deletion Prevention (rm -rf /)
10
10
  7. Network Data Exfiltration Prevention (piping secrets to curl/wget)
11
11
  8. Package Typosquatting & Hallucination Early Warning
12
+ 9. In-Place Stream Editing & Blind Line Deletion Prevention (sed -i, perl -i, awk -i inplace)
12
13
  """
13
14
 
14
15
  import os
@@ -316,6 +317,36 @@ class TokenSafeGuard:
316
317
  )
317
318
  )
318
319
 
320
+ # 1b. In-Place Stream Editing & Blind Line Mutation Prevention (sed -i, perl -i, awk -i inplace)
321
+ _NUMERIC_RANGE_RE = re.compile(r"""['"]?\s*\d+\s*(?:,\s*\d+)?\s*[ds]\b""")
322
+ for stage in stages:
323
+ cmd_tok, cmd_args = cls._stage_cmd_tokens(stage)
324
+ if cmd_tok in ("sed", "perl", "awk", "gawk"):
325
+ has_inplace = False
326
+ if cmd_tok == "sed":
327
+ has_inplace = any(a == "-i" or a.startswith("-i") or a == "--in-place" or a.startswith("--in-place=") for a in cmd_args)
328
+ elif cmd_tok == "perl":
329
+ has_inplace = any(a == "-i" or a.startswith("-i") or (a.startswith("-") and not a.startswith("--") and "i" in a) for a in cmd_args)
330
+ elif cmd_tok in ("awk", "gawk"):
331
+ has_inplace = any(a in ("inplace", "--include=inplace") or a.startswith("-i") for a in cmd_args)
332
+
333
+ has_code_target = cls._has_code_target_in_args(cmd_tok, cmd_args)
334
+ has_numeric_range = bool(_NUMERIC_RANGE_RE.search(stage))
335
+
336
+ if (has_inplace and (has_code_target or has_numeric_range)) or (has_numeric_range and has_code_target):
337
+ reason = (
338
+ f"In-place stream editing of source files blocked: '{stage}'. "
339
+ f"Modifying code with sed/perl/awk or blind line ranges causes line-drift and catastrophic code deletion. "
340
+ f"Use the structured 'edit_file' tool with exact target matching instead."
341
+ )
342
+ if "2>/dev/null" in stage or "&>/dev/null" in stage:
343
+ reason += " Stderr suppression ('2>/dev/null') was also detected, which hides execution failures."
344
+ return GuardResult(
345
+ blocked=True,
346
+ check_name="INPLACE_STREAM_EDIT",
347
+ reason=reason
348
+ )
349
+
319
350
  # 2. Git Staging Protection for Sensitive Files (.env, private keys)
320
351
  for stage in stages:
321
352
  cmd_tok, cmd_args = cls._stage_cmd_tokens(stage)
package/src/mcp_server.py CHANGED
@@ -42,7 +42,7 @@ from src.paths import get_active_workspace, is_plugin_or_system_dir
42
42
 
43
43
  SERVER_INFO = {
44
44
  "name": "tokensafe-mcp",
45
- "version": "4.2.4"
45
+ "version": "4.2.5"
46
46
  }
47
47
 
48
48
  # MCP client attribution: the initialize handshake carries clientInfo, which
@@ -217,7 +217,7 @@ TOOLS = [
217
217
  },
218
218
  {
219
219
  "name": "guard_inspect",
220
- "description": "Pre-flight security & hygiene audit for commands or code snippets. Detects secret leaks, SQL injection, TLS bypass (incl. git-level), CORS wildcard, destructive commands, raw grep, and never-terminating streams (tail -f, watch, docker attach).",
220
+ "description": "Pre-flight security & hygiene audit for commands or code snippets. Detects secret leaks, SQL injection, TLS bypass (incl. git-level), CORS wildcard, destructive commands, raw grep, in-place stream editing (sed -i, perl -i), and never-terminating streams (tail -f, watch, docker attach).",
221
221
  "inputSchema": {
222
222
  "type": "object",
223
223
  "properties": {
@@ -241,7 +241,7 @@ class TelemetrySync:
241
241
  current_last_id = last_id
242
242
  headers = {
243
243
  "Content-Type": "application/json",
244
- "User-Agent": "TokenSafe-Sync/4.2.4"
244
+ "User-Agent": "TokenSafe-Sync/4.2.5"
245
245
  }
246
246
  if active_key:
247
247
  headers["Authorization"] = f"Bearer {active_key}"
@@ -17,7 +17,7 @@ import urllib.request
17
17
  import urllib.error
18
18
  from typing import Dict, Any, Optional, Tuple
19
19
 
20
- CURRENT_VERSION = "4.2.4"
20
+ CURRENT_VERSION = "4.2.5"
21
21
  CACHE_TTL = 86400 # 24 hours
22
22
  # When the cloud is unreachable we must NOT cache the synthesized "up to date"
23
23
  # answer for a full day — otherwise an update released right after an outage