tokensafe 4.13.3 → 4.14.0

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.13.3",
2
+ "version": "4.14.0",
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
@@ -266,7 +266,7 @@ Full matrix and details: [docs/OUMV.md](docs/OUMV.md).
266
266
  Real 12-assertion oracle re-run after every step; tokens and cost from the provider's `usage`
267
267
  payload. `baseline` = file/search/command tools, `tokensafe` = this product's MCP server
268
268
  (`smart_read_file(endpoint="POST /api/…")` in one call → `apply_edits` with the hunk and inline
269
- `verify="auto"`), `oumv` = the OUMV runtime on wire 1.7.0 (`observe L3` returns the handler, its
269
+ `verify="auto"`), `oumv` = the OUMV runtime measured in November 2026 (`observe L3` returns the handler, its
270
270
  version and the same-package callees; `applyEdit mode=patch` carries an inline `verify` probe and
271
271
  an actionable `-32009`). The Go sandbox is the benchmark module plus **200 generated service
272
272
  files**; the React sandbox is a TaskManager store + component whose declared `npm test` is the
package/kimi.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokensafe",
3
- "version": "4.13.3",
3
+ "version": "4.14.0",
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.13.3",
4
+ "version": "4.14.0",
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.13.3",
4
+ "version": "4.14.0",
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/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.13.3",
6
+ "version": "4.14.0",
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.13.3",
26
+ "version": "4.14.0",
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.13.3",
42
+ "version": "4.14.0",
43
43
  "runtimeHint": "uvx",
44
44
  "transport": {
45
45
  "type": "stdio"
@@ -0,0 +1,74 @@
1
+ """Crash-safe file writes.
2
+
3
+ A process killed between ``open()`` and the final rename would leave a
4
+ truncated file, and a power loss after ``os.replace`` can lose the rename
5
+ unless the directory entry is fsynced. OUMV mutations and ``apply_edits`` are
6
+ the two places where a half-written source file is unacceptable, so both go
7
+ through this helper: same-directory temp file -> flush + fsync -> chmod ->
8
+ ``os.replace`` -> directory fsync on POSIX. Windows has no directory fsync;
9
+ ``os.replace`` there is still atomic against a process crash.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ import os
15
+ import stat
16
+ import tempfile
17
+ from typing import Optional, Union
18
+
19
+ __all__ = ["write_atomic", "write_text_atomic"]
20
+
21
+
22
+ def _fsync_directory(directory: str) -> None:
23
+ if os.name != "posix" or not hasattr(os, "O_DIRECTORY"):
24
+ return
25
+ try:
26
+ fd = os.open(directory, os.O_DIRECTORY)
27
+ except OSError:
28
+ return
29
+ try:
30
+ os.fsync(fd)
31
+ finally:
32
+ os.close(fd)
33
+
34
+
35
+ def write_atomic(path: str, data: Union[bytes, str], *, mode: Optional[int] = None,
36
+ fsync: bool = True) -> str:
37
+ """Writes ``data`` to ``path`` atomically and durably.
38
+
39
+ ``mode`` defaults to the target's current permission bits (a new file keeps
40
+ the ``mkstemp`` 0600). Returns the path.
41
+ """
42
+ abs_path = os.path.abspath(path)
43
+ directory = os.path.dirname(abs_path) or "."
44
+ os.makedirs(directory, exist_ok=True)
45
+ if mode is None and os.path.exists(abs_path):
46
+ try:
47
+ mode = stat.S_IMODE(os.stat(abs_path).st_mode)
48
+ except OSError:
49
+ mode = None
50
+
51
+ payload = data.encode("utf-8") if isinstance(data, str) else data
52
+ fd, tmp_path = tempfile.mkstemp(prefix=".tokensafe_atomic_", dir=directory)
53
+ try:
54
+ with os.fdopen(fd, "wb") as handle:
55
+ handle.write(payload)
56
+ handle.flush()
57
+ if fsync:
58
+ os.fsync(handle.fileno())
59
+ os.chmod(tmp_path, mode if mode is not None else 0o600)
60
+ os.replace(tmp_path, abs_path)
61
+ except BaseException:
62
+ try:
63
+ os.unlink(tmp_path)
64
+ except OSError:
65
+ pass
66
+ raise
67
+ if fsync:
68
+ _fsync_directory(directory)
69
+ return abs_path
70
+
71
+
72
+ def write_text_atomic(path: str, text: str, *, mode: Optional[int] = None,
73
+ fsync: bool = True) -> str:
74
+ return write_atomic(path, text, mode=mode, fsync=fsync)
@@ -1933,12 +1933,12 @@ _SIDECARS = {
1933
1933
  "spring": (
1934
1934
  "java/src/dev/tokensafe/oumv/OumvSpring.java",
1935
1935
  "OumvSpring.java",
1936
- "7d228f3eedd4d401cbbef9b0722a9d215083f926ed1ef8e083c58456205595c4",
1936
+ "edcb33b5c250ef6a087f20efe4fd9ebd8519f03e2f6f2f8484ff26835cf06694",
1937
1937
  ),
1938
1938
  "php": (
1939
1939
  "php/bin/oumv-php",
1940
1940
  "oumv-php",
1941
- "7f2939cf909d91dbbe6cf92295e5db0141f8b3533127a7bbc59bfad3d388b8b3",
1941
+ "ed61eabc1cd92b775a014a380f393922a3046a476ef9ed24d63a083623efefb2",
1942
1942
  ),
1943
1943
  }
1944
1944
 
@@ -10,7 +10,7 @@ from __future__ import annotations
10
10
 
11
11
  # Backend tag (`vX.Y.Z`); the Go module resolves against the matching `go/vX.Y.Z`,
12
12
  # which the backend release workflow creates alongside it.
13
- BACKEND_RELEASE_TAG = "v0.20.0"
13
+ BACKEND_RELEASE_TAG = "v0.21.0"
14
14
 
15
15
  # Wire version that tag speaks. Printed in briefs so an agent never mixes a
16
16
  # backend release with an older protocol line.
@@ -19,9 +19,9 @@ BACKEND_WIRE_VERSION = "1.8.0"
19
19
  # npm release of `tokensafe-backend-node` that ships the same adapters. The
20
20
  # package has its own semver line (`node/package.json`), so it is pinned
21
21
  # separately from the Go tag; `tokensafe inject` installs exactly this version.
22
- BACKEND_NPM_VERSION = "0.15.0"
22
+ BACKEND_NPM_VERSION = "0.16.0"
23
23
 
24
24
  # NuGet release of `TokenSafe.Oumv.AspNetCore`. It has its own semver line too
25
25
  # (`dotnet/src/TokenSafe.Oumv/TokenSafe.Oumv.csproj`), so tying it to the Go tag
26
26
  # would ask NuGet for a version that does not exist.
27
- BACKEND_DOTNET_VERSION = "0.7.0"
27
+ BACKEND_DOTNET_VERSION = "0.8.0"
@@ -304,20 +304,8 @@ def _normalize_eol(text: str, newline: str) -> str:
304
304
  def _write_atomic(abs_path: str, content: str, mode: Optional[int]) -> None:
305
305
  """Writes through a same-directory temp file + os.replace, so a failed write
306
306
  never leaves a truncated target. Preserves `mode` when provided."""
307
- directory = os.path.dirname(abs_path) or "."
308
- fd, tmp_path = tempfile.mkstemp(prefix=".tokensafe_edit_", dir=directory)
309
- try:
310
- with os.fdopen(fd, "w", encoding="utf-8", newline="") as f:
311
- f.write(content)
312
- if mode is not None:
313
- os.chmod(tmp_path, stat.S_IMODE(mode))
314
- os.replace(tmp_path, abs_path)
315
- except BaseException:
316
- try:
317
- os.unlink(tmp_path)
318
- except OSError:
319
- pass
320
- raise
307
+ from src.atomic_io import write_text_atomic
308
+ write_text_atomic(abs_path, content, mode=stat.S_IMODE(mode) if mode is not None else None)
321
309
 
322
310
 
323
311
  def _apply_hunk_to_text(
package/src/mcp_server.py CHANGED
@@ -46,7 +46,7 @@ from src.session_context import current_root, current_session_id
46
46
 
47
47
  SERVER_INFO = {
48
48
  "name": "tokensafe-mcp",
49
- "version": "4.13.3"
49
+ "version": "4.14.0"
50
50
  }
51
51
 
52
52
  # MCP client attribution: the initialize handshake carries clientInfo, which
@@ -351,6 +351,42 @@ class OUMVGateway:
351
351
  removed.append(path)
352
352
  return removed
353
353
 
354
+ @classmethod
355
+ def prune_backups(cls, workspace_dir: str, *, keep_per_file: int = 20,
356
+ max_age_days: int = 30) -> List[str]:
357
+ """Bounds ``.tokensafe/backups``: the newest ``keep_per_file`` per source
358
+ file and nothing older than ``max_age_days``. Best-effort by design — a
359
+ retention failure must never fail the mutation that triggered it."""
360
+ directory = os.path.join(workspace_dir, ".tokensafe", "backups")
361
+ if not os.path.isdir(directory):
362
+ return []
363
+ try:
364
+ entries = list(os.scandir(directory))
365
+ except OSError:
366
+ return []
367
+ groups: Dict[str, List[Any]] = {}
368
+ for entry in entries:
369
+ if not entry.is_file() or not entry.name.endswith(".bak"):
370
+ continue
371
+ stem = entry.name.split("_", 1)[1] if "_" in entry.name else entry.name
372
+ groups.setdefault(stem, []).append(entry)
373
+ now = time.time()
374
+ removed: List[str] = []
375
+ for backups in groups.values():
376
+ backups.sort(key=lambda item: item.stat().st_mtime, reverse=True)
377
+ for index, entry in enumerate(backups):
378
+ try:
379
+ age_days = (now - entry.stat().st_mtime) / 86400
380
+ except OSError:
381
+ continue
382
+ if index >= keep_per_file or age_days > max_age_days:
383
+ try:
384
+ os.unlink(entry.path)
385
+ removed.append(entry.path)
386
+ except OSError:
387
+ pass
388
+ return removed
389
+
354
390
  @classmethod
355
391
  def _probe_candidates(cls, urls: List[str], kind: str) -> Optional[Dict[str, Any]]:
356
392
  for url in urls:
@@ -1145,16 +1181,19 @@ class OUMVGateway:
1145
1181
  os.makedirs(backup_dir, exist_ok=True)
1146
1182
  digest = hashlib.sha256(content).hexdigest()[:8]
1147
1183
  backup_path = os.path.join(backup_dir, f"{digest}_{os.path.basename(abs_path)}.bak")
1148
- with open(backup_path, "wb") as f:
1149
- f.write(content)
1184
+ from src.atomic_io import write_atomic
1185
+ write_atomic(backup_path, content)
1150
1186
  except Exception:
1151
1187
  backup_path = None
1152
1188
 
1153
- os.makedirs(os.path.dirname(abs_path), exist_ok=True)
1154
- with open(abs_path, "w", encoding="utf-8") as f:
1155
- f.write(new_content)
1189
+ from src.atomic_io import write_atomic
1190
+ write_atomic(abs_path, new_content)
1156
1191
 
1157
1192
  new_version = "sha256:" + hashlib.sha256(new_content.encode("utf-8")).hexdigest()
1193
+ try:
1194
+ OUMVGateway.prune_backups(ws)
1195
+ except Exception:
1196
+ pass
1158
1197
  result = {
1159
1198
  "success": True,
1160
1199
  "path": path,
package/src/retrofit.py CHANGED
@@ -11,6 +11,8 @@ import time
11
11
  from pathlib import Path
12
12
  from typing import Dict, Any, List, Optional, Tuple
13
13
 
14
+ from src.backend_release import BACKEND_NPM_VERSION, BACKEND_WIRE_VERSION
15
+
14
16
  # Top-level directories that hold frontend source in a repo-root app (as opposed to
15
17
  # scripts/, tooling/ and configs, which are .ts/.js but not OUMV-observable).
16
18
  _FRONTEND_SOURCE_DIRS = frozenset({
@@ -808,7 +810,7 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
808
810
  "technology": {
809
811
  "language": "typescript",
810
812
  "framework": "express | fastify",
811
- "package": {"manager": "npm", "name": "tokensafe-backend-node", "install": "npm install tokensafe-backend-node"},
813
+ "package": {"manager": "npm", "name": "tokensafe-backend-node", "install": f"npm install tokensafe-backend-node@{BACKEND_NPM_VERSION}"},
812
814
  },
813
815
  "capabilities": [
814
816
  {"name": "observe.pulse", "constraints": {"readOnly": True, "developmentOnly": True}},
@@ -834,7 +836,7 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
834
836
  "technology": {
835
837
  "language": "typescript",
836
838
  "framework": "elysia (bun)",
837
- "package": {"manager": "bun", "name": "tokensafe-backend-node", "install": "bun add tokensafe-backend-node"},
839
+ "package": {"manager": "bun", "name": "tokensafe-backend-node", "install": f"bun add tokensafe-backend-node@{BACKEND_NPM_VERSION}"},
838
840
  },
839
841
  "capabilities": [
840
842
  {"name": "observe.pulse", "constraints": {"readOnly": True, "developmentOnly": True}},
@@ -862,7 +864,7 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
862
864
  "technology": {
863
865
  "language": "typescript",
864
866
  "framework": "next (app router)",
865
- "package": {"manager": "npm", "name": "tokensafe-backend-node", "install": "npm install --save-dev tokensafe-backend-node"},
867
+ "package": {"manager": "npm", "name": "tokensafe-backend-node", "install": f"npm install --save-dev tokensafe-backend-node@{BACKEND_NPM_VERSION}"},
866
868
  },
867
869
  "capabilities": [
868
870
  {"name": "observe.pulse", "constraints": {"readOnly": True, "developmentOnly": True}},
@@ -886,7 +888,7 @@ def get_adapters_catalog() -> List[Dict[str, Any]]:
886
888
  "repo": "tokensafe-backend/dotnet",
887
889
  "mode": "hybrid",
888
890
  "status": "ready",
889
- "description": "In-process endpoint dispatch for minimal APIs and controllers, Roslyn syntax pre-flight, the full wire 1.6.0 surface (previewEdit, index, query, build, cancel), and verify.sandboxRollback that rolls every auto-discovered EF Core DbContext back",
891
+ "description": f"In-process endpoint dispatch for minimal APIs and controllers, Roslyn syntax pre-flight, the full wire {BACKEND_WIRE_VERSION} surface (previewEdit, index, query, build, cancel), and verify.sandboxRollback that rolls every auto-discovered EF Core DbContext back",
890
892
  "technology": {
891
893
  "language": "csharp",
892
894
  "framework": "aspnetcore",
@@ -311,7 +311,7 @@ class TelemetrySync:
311
311
  current_last_id = last_id
312
312
  headers = {
313
313
  "Content-Type": "application/json",
314
- "User-Agent": "TokenSafe-Sync/4.13.3"
314
+ "User-Agent": "TokenSafe-Sync/4.14.0"
315
315
  }
316
316
  if active_key:
317
317
  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.13.3"
20
+ CURRENT_VERSION = "4.14.0"
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