tokensafe 4.7.17 → 4.7.18

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.7.17",
2
+ "version": "4.7.18",
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
@@ -510,6 +510,8 @@ All hook adapters fail open: an internal error never stalls your agent. Failures
510
510
  | `oumv_understand` | Query runtime causality, state dependencies, and backend route mappings |
511
511
  | `oumv_mutate` | OCC-guarded source edits (`expectedVersion` from `observe` → `file.version`, path jail, syntax pre-flight, backup). A `symbol` edit splices that declaration only, with or without a live runtime |
512
512
  | `oumv_verify` | Transactional verification and state invariant assertions |
513
+
514
+ Observation is free on every plan. The write tools (`oumv_mutate`, `oumv_preview`, `oumv_verify`, `oumv_build`) need Solo or higher: guest and free run OUMV's read-only profile, where those methods are absent and answer `-32601`.
513
515
  </details>
514
516
 
515
517
  <details>
@@ -613,7 +615,7 @@ TokenSafe integrates with the [OUMV Protocol](https://github.com/tokensafe-dev/o
613
615
  - **Consolidated Adapters**:
614
616
  - **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).
615
617
  - **Backend**: Go (`gin`, `chi`, `stdhttp`) and Python (`fastapi`, `sqlalchemy`) in [`tokensafe-backend`](https://github.com/tokensafe-dev/tokensafe-backend).
616
- - **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`.
618
+ - **Guarded Mutations, Enabled by Default**: `oumv_mutate` works out of the box on Solo and above 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`.
617
619
  - **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.
618
620
  - **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.
619
621
 
package/kimi.plugin.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tokensafe",
3
- "version": "4.7.17",
3
+ "version": "4.7.18",
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.7.17",
4
+ "version": "4.7.18",
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.7.17",
4
+ "version": "4.7.18",
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.7.17",
6
+ "version": "4.7.18",
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.7.17",
26
+ "version": "4.7.18",
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.7.17",
42
+ "version": "4.7.18",
43
43
  "runtimeHint": "uvx",
44
44
  "transport": {
45
45
  "type": "stdio"
@@ -27,6 +27,7 @@ import shutil
27
27
  import subprocess
28
28
  from typing import Any, Dict, List, Optional, Tuple
29
29
 
30
+ from src import oumv_policy
30
31
  from src.retrofit import detect_project_stack, generate_config, get_adapters_catalog
31
32
 
32
33
  _PYHOOKS_DIRNAME = "pyhooks"
@@ -200,13 +201,18 @@ def backend_env(env: Optional[Dict[str, str]] = None) -> Dict[str, str]:
200
201
  hook = pyhooks_dir()
201
202
  base["PYTHONPATH"] = f"{hook}{os.pathsep}{existing}" if existing else hook
202
203
  base["TOKENSAFE_OUMV_AUTOMOUNT"] = "1"
204
+ if oumv_policy.current()[0] == oumv_policy.PROFILE_READ_ONLY:
205
+ base["TOKENSAFE_OUMV_READ_ONLY"] = "1"
203
206
  return base
204
207
 
205
208
 
206
209
  def python_run_hint(workspace: str) -> str:
207
210
  """The command an agent should use to start a FastAPI dev server with OUMV."""
211
+ prefix = ""
212
+ if oumv_policy.current()[0] == oumv_policy.PROFILE_READ_ONLY:
213
+ prefix = "TOKENSAFE_OUMV_READ_ONLY=1 "
208
214
  return (
209
- f'TOKENSAFE_OUMV_AUTOMOUNT=1 PYTHONPATH="{pyhooks_dir()}:$PYTHONPATH" '
215
+ f'{prefix}TOKENSAFE_OUMV_AUTOMOUNT=1 PYTHONPATH="{pyhooks_dir()}:$PYTHONPATH" '
210
216
  "uvicorn <module:app> --reload"
211
217
  )
212
218
 
@@ -1163,8 +1169,11 @@ def sidecar_run_command(kind: str, sidecar_path: str, workspace: str) -> Optiona
1163
1169
  """The exact command that starts the sidecar against `workspace`."""
1164
1170
  if not sidecar_path:
1165
1171
  return None
1172
+ # Java only knows the CLI flag; the PHP sidecar also reads OUMV_READ_ONLY,
1173
+ # which run-backend sets, so its command line stays unchanged.
1174
+ read_only = " --read-only" if oumv_policy.current()[0] == oumv_policy.PROFILE_READ_ONLY else ""
1166
1175
  if kind == "spring":
1167
- return f"tokensafe run-backend java {sidecar_path} --root {workspace} --port 7331"
1176
+ return f"tokensafe run-backend java {sidecar_path} --root {workspace} --port 7331{read_only}"
1168
1177
  if kind == "php":
1169
1178
  return f"tokensafe run-backend php -S 127.0.0.1:7332 {sidecar_path} --root {workspace}"
1170
1179
  return None
package/src/cli.py CHANGED
@@ -22,6 +22,7 @@ from src.metrics import MetricsTracker
22
22
  from src.dashboard import Dashboard, render_bar
23
23
  from src.compactor import PromptCompactor
24
24
  from src.tokenizer import count_tokens
25
+ from src import oumv_policy
25
26
 
26
27
  def summarize_unittest_output(raw: str, full_traceback: bool = False) -> str:
27
28
  """Compacts `python3 -m unittest discover` output to what a developer
@@ -270,6 +271,11 @@ def main(argv: Optional[List[str]] = None):
270
271
  print(f" Booster: Cloud Prompt Booster {state}")
271
272
  except Exception:
272
273
  pass
274
+ profile, _sextant_tier = oumv_policy.current()
275
+ if profile == oumv_policy.PROFILE_READ_ONLY:
276
+ print(f" Sextant: \033[33mread-only\033[0m (observe everywhere; change/verify on Solo+)")
277
+ else:
278
+ print(f" Sextant: \033[32mfull\033[0m (change and verify the running app)")
273
279
  # Verifiable egress transparency: what left this machine today
274
280
  try:
275
281
  from src.egress_counter import today_counts
@@ -773,7 +779,9 @@ def main(argv: Optional[List[str]] = None):
773
779
  return
774
780
  if os.path.basename(tool) in ("java", "php", "node", "npm", "npx"):
775
781
  print(f"⚡ Launching {os.path.basename(tool)} with the Sextant runtime")
776
- os.execvpe(resolved, argv_rest, dict(os.environ))
782
+ # Go/Node/.NET and the PHP sidecar read the env; Java takes the CLI
783
+ # flag, which `sidecar_run_command` already appends.
784
+ os.execvpe(resolved, argv_rest, oumv_policy.spawn_env())
777
785
  ensure_python_autoload()
778
786
  env = backend_env()
779
787
  os.execvpe(resolved, argv_rest, env)
@@ -913,7 +921,9 @@ def main(argv: Optional[List[str]] = None):
913
921
  target_dir, port=port_val, host=host_val, open_browser=open_browser
914
922
  )
915
923
  print(f"⚡ Launching Zero-Footprint Vite OUMV server ({source})...")
916
- proc = subprocess.run(cmd, cwd=target_dir)
924
+ # The Vite bridge is a process-start profile: a free license must never
925
+ # advertise write methods the engine would refuse anyway.
926
+ proc = subprocess.run(cmd, cwd=target_dir, env=oumv_policy.spawn_env())
917
927
  sys.exit(proc.returncode)
918
928
 
919
929
  elif command in ("bench-oumv", "bench_oumv"):
@@ -1702,6 +1712,11 @@ def main(argv: Optional[List[str]] = None):
1702
1712
  print(f" Expires: {dt}")
1703
1713
  else:
1704
1714
  print(f" Expires: Never (Lifetime)")
1715
+ profile, _sextant_tier = oumv_policy.current()
1716
+ if profile == oumv_policy.PROFILE_READ_ONLY:
1717
+ print(" Sextant: read-only (observe everywhere; change/verify on Solo+)")
1718
+ else:
1719
+ print(" Sextant: full (change and verify the running app)")
1705
1720
  print()
1706
1721
 
1707
1722
  elif command in ("booster",):
package/src/mcp_server.py CHANGED
@@ -38,13 +38,14 @@ from src.diff_slicer import DiffSlicer
38
38
  from src.guard import TokenSafeGuard
39
39
  from src.scoped_search import ScopedSearch
40
40
  from src import route_index
41
+ from src import oumv_policy
41
42
  from src.license_manager import LicenseManager
42
43
  from src.paths import get_active_workspace, is_plugin_or_system_dir
43
44
  from src.session_context import current_root, current_session_id
44
45
 
45
46
  SERVER_INFO = {
46
47
  "name": "tokensafe-mcp",
47
- "version": "4.7.17"
48
+ "version": "4.7.18"
48
49
  }
49
50
 
50
51
  # MCP client attribution: the initialize handshake carries clientInfo, which
@@ -843,7 +844,9 @@ TOOLS = [{'name': 'smart_read_file',
843
844
  'annotations': {'readOnlyHint': False},
844
845
  'description': "OUMV runtime: 'status'|'observe' L0-L4|'understand'|'verify'|'mutate' (OCC edit)|'graph'|'index' "
845
846
  "(repo-wide symbol search: query, kinds?, limit?)|'preview' (dry-run diff, no write)|'build' "
846
- "(run the runtime's build/test command, §14.3)|'cancel' (cooperative, by requestId).",
847
+ "(run the runtime's build/test command, §14.3)|'cancel' (cooperative, by requestId). "
848
+ "Observation is free on every plan; the write actions (verify, mutate, preview, build) "
849
+ "need Solo or higher and are refused with a read-only notice on guest/free.",
847
850
  'inputSchema': {'type': 'object',
848
851
  'properties': {'action': {'type': 'string',
849
852
  'enum': ['status',
@@ -2103,6 +2106,12 @@ def _dispatch_tool_call(name: str, args: dict) -> dict:
2103
2106
  quota = LicenseManager.check_quota(tracker)
2104
2107
  is_quota_exceeded = bool(quota.get("is_quota_exceeded", False))
2105
2108
 
2109
+ # Observation is free on every plan; the OUMV write profile is licensed, not
2110
+ # metered. Refuse exactly where a read-only adapter has no method at all, so
2111
+ # a hand-mounted read-write runtime cannot be driven by a free license either.
2112
+ if name in oumv_policy.WRITE_TOOLS and oumv_policy.current()[0] == oumv_policy.PROFILE_READ_ONLY:
2113
+ return _fallback_error(name, oumv_policy.deny_text(name))
2114
+
2106
2115
  if name == "smart_read_file":
2107
2116
  path = args.get("path") or args.get("file_path") or args.get("file") or ""
2108
2117
  symbol = args.get("symbol") or args.get("sym") or args.get("target") or ""
@@ -0,0 +1,114 @@
1
+ """Per-tier OUMV capability policy.
2
+
3
+ Observation is free on every plan. Changing or verifying a running app
4
+ (``mutate``, ``preview``, ``verify``, ``build``) needs a paid tier, because those
5
+ are the runtime's write path: the adapters implement the read-only deployment
6
+ profile by not registering the methods at all, so a read-only runtime answers
7
+ ``-32601`` before session validation and advertises ``capabilities.readOnly`` in
8
+ the handshake (spec §8.5).
9
+
10
+ Precedence:
11
+
12
+ 1. ``TOKENSAFE_OUMV_READ_ONLY`` truthy -> read-only (operator switch, always wins)
13
+ 2. a signed license payload key ``oumv_profile`` (``read_only`` / ``full``)
14
+ 3. the tier map: guest/free -> read-only, solo/team/enterprise -> full
15
+
16
+ The tier comes from an Ed25519-signed payload, so the map is policy, not an
17
+ entitlement check: it cannot be edited into a paid tier. A future server-signed
18
+ ``oumv_profile`` needs no engine change because ``validate_license`` returns the
19
+ signed payload unfiltered.
20
+ """
21
+
22
+ from __future__ import annotations
23
+
24
+ import os
25
+ from typing import Any, Dict, Optional, Tuple
26
+
27
+ PROFILE_READ_ONLY = "read_only"
28
+ PROFILE_FULL = "full"
29
+
30
+ FULL_TIERS = frozenset({"solo", "team", "enterprise"})
31
+
32
+ # Tools whose adapters are absent in the read-only deployment profile. Mirrors
33
+ # READ_ONLY_ABSENT_METHODS in tokensafe-backend (python/.../core/runtime.py).
34
+ WRITE_TOOLS = frozenset({
35
+ "oumv_mutate",
36
+ "oumv_preview",
37
+ "oumv_verify",
38
+ "oumv_build",
39
+ })
40
+
41
+ _TRUTHY = frozenset({"1", "true", "yes", "on"})
42
+ _READ_ONLY_ALIASES = frozenset({"read_only", "read-only", "readonly"})
43
+
44
+
45
+ def _env_forces_read_only() -> bool:
46
+ raw = (os.environ.get("TOKENSAFE_OUMV_READ_ONLY") or "").strip().lower()
47
+ return raw in _TRUTHY
48
+
49
+
50
+ def _signed_profile(payload: Optional[Dict[str, Any]]) -> Optional[str]:
51
+ raw = str((payload or {}).get("oumv_profile") or "").strip().lower()
52
+ if raw in _READ_ONLY_ALIASES:
53
+ return PROFILE_READ_ONLY
54
+ if raw == PROFILE_FULL:
55
+ return PROFILE_FULL
56
+ return None
57
+
58
+
59
+ def profile_for(tier: Optional[str] = None, payload: Optional[Dict[str, Any]] = None) -> str:
60
+ """Resolves the OUMV profile for a tier (and an optional signed payload)."""
61
+ if _env_forces_read_only():
62
+ return PROFILE_READ_ONLY
63
+ signed = _signed_profile(payload)
64
+ if signed is not None:
65
+ return signed
66
+ if str(tier or "").strip().lower() in FULL_TIERS:
67
+ return PROFILE_FULL
68
+ return PROFILE_READ_ONLY
69
+
70
+
71
+ def current() -> Tuple[str, str]:
72
+ """(profile, tier) for the active license. License reads are cached upstream."""
73
+ from src.license_manager import LicenseManager
74
+
75
+ try:
76
+ tier, payload = LicenseManager.get_active_license()
77
+ except Exception:
78
+ return PROFILE_READ_ONLY, "guest"
79
+ return profile_for(tier, payload), str(tier or "guest").strip().lower() or "guest"
80
+
81
+
82
+ def is_read_only(tier: Optional[str] = None, payload: Optional[Dict[str, Any]] = None) -> bool:
83
+ if tier is None and payload is None:
84
+ return current()[0] == PROFILE_READ_ONLY
85
+ return profile_for(tier, payload) == PROFILE_READ_ONLY
86
+
87
+
88
+ def spawn_env(env: Optional[Dict[str, str]] = None) -> Dict[str, str]:
89
+ """Environment for a spawned runtime: read-only flags only when licensed so.
90
+
91
+ Node/Go/.NET and the generated Python sitecustomize read
92
+ ``TOKENSAFE_OUMV_READ_ONLY``; the PHP sidecar reads ``OUMV_READ_ONLY``. Java
93
+ takes the CLI flag instead (see ``sidecar_run_command``).
94
+ """
95
+ base = dict(os.environ if env is None else env)
96
+ if current()[0] == PROFILE_READ_ONLY:
97
+ base["TOKENSAFE_OUMV_READ_ONLY"] = "1"
98
+ base["OUMV_READ_ONLY"] = "1"
99
+ return base
100
+
101
+
102
+ def deny_text(target: str) -> str:
103
+ """Refusal that mirrors the adapter's absent method instead of a quota banner."""
104
+ action = str(target or "").strip()
105
+ if action.startswith("oumv_"):
106
+ action = action[len("oumv_"):]
107
+ action = action or "mutate"
108
+ return (
109
+ f"'{action}' is a write-profile method and this license is read-only (free plan). "
110
+ "Observation stays free: use status, observe, understand, graph or index. "
111
+ "Change and verify the running app on Solo or higher "
112
+ "(https://tokensafe.dev/pricing). Restart the dev server after upgrading so "
113
+ "the runtime re-registers the write methods."
114
+ )
@@ -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.7.17"
314
+ "User-Agent": "TokenSafe-Sync/4.7.18"
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.7.17"
20
+ CURRENT_VERSION = "4.7.18"
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