meshcode 2.5.7__tar.gz → 2.5.8__tar.gz
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.
- {meshcode-2.5.7 → meshcode-2.5.8}/PKG-INFO +1 -1
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/__init__.py +1 -1
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/meshcode_mcp/backend.py +90 -8
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/meshcode_mcp/server.py +11 -2
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode.egg-info/PKG-INFO +1 -1
- {meshcode-2.5.7 → meshcode-2.5.8}/pyproject.toml +1 -1
- {meshcode-2.5.7 → meshcode-2.5.8}/README.md +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/cli.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/comms_v4.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/invites.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/launcher.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/launcher_install.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/meshcode_mcp/__init__.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/meshcode_mcp/__main__.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/meshcode_mcp/realtime.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/meshcode_mcp/test_backend.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/meshcode_mcp/test_realtime.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/meshcode_mcp/test_server_wrapper.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/preferences.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/protocol_v2.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/run_agent.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/secrets.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/self_update.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode/setup_clients.py +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode.egg-info/SOURCES.txt +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode.egg-info/dependency_links.txt +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode.egg-info/entry_points.txt +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode.egg-info/requires.txt +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/meshcode.egg-info/top_level.txt +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/setup.cfg +0 -0
- {meshcode-2.5.7 → meshcode-2.5.8}/tests/test_status_enum_coverage.py +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
"""MeshCode — Real-time communication between AI agents."""
|
|
2
|
-
__version__ = "2.5.
|
|
2
|
+
__version__ = "2.5.8"
|
|
@@ -244,8 +244,8 @@ def send_message(project_id: str, from_agent: str, to_agent: str, payload: Any,
|
|
|
244
244
|
if encrypted and api_key:
|
|
245
245
|
mesh_key = get_mesh_key(api_key, project_id)
|
|
246
246
|
if mesh_key:
|
|
247
|
-
encrypted_data = encrypt_payload(payload, mesh_key)
|
|
248
|
-
payload = {"_encrypted": encrypted_data}
|
|
247
|
+
encrypted_data = encrypt_payload(payload, mesh_key, aad=project_id)
|
|
248
|
+
payload = {"_encrypted": encrypted_data, "_aad": project_id}
|
|
249
249
|
actual_encrypted = True
|
|
250
250
|
|
|
251
251
|
# Use validated SECURITY DEFINER RPC when api_key is provided
|
|
@@ -302,6 +302,55 @@ def send_message(project_id: str, from_agent: str, to_agent: str, payload: Any,
|
|
|
302
302
|
|
|
303
303
|
|
|
304
304
|
def read_inbox(project_id: str, agent: str, mark_read: bool = True, api_key: Optional[str] = None) -> List[Dict]:
|
|
305
|
+
# Use SECURITY DEFINER RPC when api_key is available (bypasses RLS safely)
|
|
306
|
+
if api_key:
|
|
307
|
+
rpc_result = sb_rpc("mc_read_inbox", {
|
|
308
|
+
"p_api_key": api_key,
|
|
309
|
+
"p_project_id": project_id,
|
|
310
|
+
"p_agent_name": agent,
|
|
311
|
+
"p_mark_read": mark_read,
|
|
312
|
+
})
|
|
313
|
+
if isinstance(rpc_result, dict) and rpc_result.get("ok"):
|
|
314
|
+
messages = rpc_result.get("messages", [])
|
|
315
|
+
if isinstance(messages, list):
|
|
316
|
+
# Auto-decrypt and ACK (mark_read already handled by RPC)
|
|
317
|
+
mesh_key = None
|
|
318
|
+
for m in messages:
|
|
319
|
+
p = m.get("payload")
|
|
320
|
+
if isinstance(p, dict) and "_encrypted" in p:
|
|
321
|
+
if mesh_key is None:
|
|
322
|
+
mesh_key = get_mesh_key(api_key, project_id)
|
|
323
|
+
if mesh_key:
|
|
324
|
+
decrypted = decrypt_payload(p["_encrypted"], mesh_key)
|
|
325
|
+
if decrypted is not None:
|
|
326
|
+
m["payload"] = decrypted
|
|
327
|
+
m["_was_encrypted"] = True
|
|
328
|
+
if mark_read and messages:
|
|
329
|
+
import datetime as _dt
|
|
330
|
+
now = _dt.datetime.now(_dt.timezone.utc)
|
|
331
|
+
def _is_stale_rpc(m):
|
|
332
|
+
ts = m.get("created_at")
|
|
333
|
+
if not ts:
|
|
334
|
+
return True
|
|
335
|
+
try:
|
|
336
|
+
dt = _dt.datetime.fromisoformat(str(ts).replace("Z", "+00:00"))
|
|
337
|
+
return (now - dt).total_seconds() > 60
|
|
338
|
+
except Exception:
|
|
339
|
+
return True
|
|
340
|
+
ack_targets = {
|
|
341
|
+
m.get("from_agent", "")
|
|
342
|
+
for m in messages
|
|
343
|
+
if m.get("type") not in ("ack", "broadcast") and _is_stale_rpc(m)
|
|
344
|
+
}
|
|
345
|
+
for sender in ack_targets:
|
|
346
|
+
if sender:
|
|
347
|
+
send_message(project_id, agent, sender,
|
|
348
|
+
{"text": f"{agent} read your message"},
|
|
349
|
+
msg_type="ack", api_key=api_key)
|
|
350
|
+
return messages
|
|
351
|
+
# If RPC doesn't exist yet, fall through to direct query
|
|
352
|
+
|
|
353
|
+
# Fallback: direct SELECT (tests/legacy — requires anon RLS bypass)
|
|
305
354
|
messages = sb_select(
|
|
306
355
|
"mc_messages",
|
|
307
356
|
f"project_id=eq.{project_id}&to_agent=eq.{quote(agent)}&read=eq.false",
|
|
@@ -365,7 +414,19 @@ def read_inbox(project_id: str, agent: str, mark_read: bool = True, api_key: Opt
|
|
|
365
414
|
return messages
|
|
366
415
|
|
|
367
416
|
|
|
368
|
-
def count_pending(project_id: str, agent: str) -> int:
|
|
417
|
+
def count_pending(project_id: str, agent: str, api_key: Optional[str] = None) -> int:
|
|
418
|
+
# Use SECURITY DEFINER RPC when api_key is available
|
|
419
|
+
if api_key:
|
|
420
|
+
result = sb_rpc("mc_count_pending", {
|
|
421
|
+
"p_api_key": api_key,
|
|
422
|
+
"p_project_id": project_id,
|
|
423
|
+
"p_agent_name": agent,
|
|
424
|
+
})
|
|
425
|
+
if isinstance(result, dict) and result.get("ok"):
|
|
426
|
+
return result.get("count", 0)
|
|
427
|
+
# Fall through to direct query if RPC doesn't exist yet
|
|
428
|
+
|
|
429
|
+
# Fallback: direct SELECT (tests/legacy)
|
|
369
430
|
pending = sb_select(
|
|
370
431
|
"mc_messages",
|
|
371
432
|
f"project_id=eq.{project_id}&to_agent=eq.{quote(agent)}&read=eq.false&type=neq.ack",
|
|
@@ -396,8 +457,15 @@ def get_mesh_key(api_key: str, project_id: str) -> Optional[str]:
|
|
|
396
457
|
return None
|
|
397
458
|
|
|
398
459
|
|
|
399
|
-
def encrypt_payload(payload: Dict, hex_key: str) -> str:
|
|
400
|
-
"""Encrypt a JSON payload using AES-256-GCM
|
|
460
|
+
def encrypt_payload(payload: Dict, hex_key: str, aad: Optional[str] = None) -> str:
|
|
461
|
+
"""Encrypt a JSON payload using AES-256-GCM with optional AAD.
|
|
462
|
+
|
|
463
|
+
Args:
|
|
464
|
+
payload: JSON-serializable dict to encrypt.
|
|
465
|
+
hex_key: Hex-encoded AES-256 key.
|
|
466
|
+
aad: Additional Authenticated Data (e.g. project_id) to bind
|
|
467
|
+
ciphertext to context and prevent replay/swap attacks.
|
|
468
|
+
"""
|
|
401
469
|
import base64
|
|
402
470
|
try:
|
|
403
471
|
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
|
@@ -406,14 +474,19 @@ def encrypt_payload(payload: Dict, hex_key: str) -> str:
|
|
|
406
474
|
key = bytes.fromhex(hex_key)
|
|
407
475
|
nonce = os.urandom(12) # 96-bit nonce for GCM
|
|
408
476
|
plaintext = json.dumps(payload).encode("utf-8")
|
|
477
|
+
aad_bytes = aad.encode("utf-8") if aad else None
|
|
409
478
|
aesgcm = AESGCM(key)
|
|
410
|
-
ciphertext = aesgcm.encrypt(nonce, plaintext,
|
|
479
|
+
ciphertext = aesgcm.encrypt(nonce, plaintext, aad_bytes)
|
|
411
480
|
# Format: base64(nonce + ciphertext)
|
|
412
481
|
return base64.b64encode(nonce + ciphertext).decode("ascii")
|
|
413
482
|
|
|
414
483
|
|
|
415
|
-
def decrypt_payload(encrypted_b64: str, hex_key: str) -> Optional[Dict]:
|
|
416
|
-
"""Decrypt an AES-256-GCM encrypted payload. Returns None on failure.
|
|
484
|
+
def decrypt_payload(encrypted_b64: str, hex_key: str, aad: Optional[str] = None) -> Optional[Dict]:
|
|
485
|
+
"""Decrypt an AES-256-GCM encrypted payload. Returns None on failure.
|
|
486
|
+
|
|
487
|
+
Tries with AAD first, falls back to no-AAD for backward compat
|
|
488
|
+
with messages encrypted before AAD was added.
|
|
489
|
+
"""
|
|
417
490
|
import base64
|
|
418
491
|
try:
|
|
419
492
|
from cryptography.hazmat.primitives.ciphers.aead import AESGCM
|
|
@@ -425,6 +498,15 @@ def decrypt_payload(encrypted_b64: str, hex_key: str) -> Optional[Dict]:
|
|
|
425
498
|
nonce = raw[:12]
|
|
426
499
|
ciphertext = raw[12:]
|
|
427
500
|
aesgcm = AESGCM(key)
|
|
501
|
+
aad_bytes = aad.encode("utf-8") if aad else None
|
|
502
|
+
# Try with AAD first
|
|
503
|
+
if aad_bytes:
|
|
504
|
+
try:
|
|
505
|
+
plaintext = aesgcm.decrypt(nonce, ciphertext, aad_bytes)
|
|
506
|
+
return json.loads(plaintext.decode("utf-8"))
|
|
507
|
+
except Exception:
|
|
508
|
+
pass # Fall through to no-AAD for backward compat
|
|
509
|
+
# Try without AAD (legacy messages)
|
|
428
510
|
plaintext = aesgcm.decrypt(nonce, ciphertext, None)
|
|
429
511
|
return json.loads(plaintext.decode("utf-8"))
|
|
430
512
|
except Exception:
|
|
@@ -1148,6 +1148,7 @@ def meshcode_send(to: str, message: Any, in_reply_to: Optional[str] = None,
|
|
|
1148
1148
|
"p_api_key": api_key,
|
|
1149
1149
|
"p_source_project": PROJECT_NAME,
|
|
1150
1150
|
"p_target_project": target_meshwork,
|
|
1151
|
+
"p_agent_name": AGENT_NAME,
|
|
1151
1152
|
})
|
|
1152
1153
|
if not isinstance(key_result, dict) or not key_result.get("ok"):
|
|
1153
1154
|
err = key_result.get("error", "unknown") if isinstance(key_result, dict) else "RPC failed"
|
|
@@ -1426,7 +1427,7 @@ def meshcode_check(include_acks: bool = False, since: Optional[str] = None) -> D
|
|
|
1426
1427
|
since: ISO-8601 timestamp. Only return messages newer than this.
|
|
1427
1428
|
Use meshcode_remember("last_seen", ts) to persist across sessions.
|
|
1428
1429
|
"""
|
|
1429
|
-
pending = be.count_pending(_PROJECT_ID, AGENT_NAME)
|
|
1430
|
+
pending = be.count_pending(_PROJECT_ID, AGENT_NAME, api_key=_get_api_key())
|
|
1430
1431
|
# Peek at realtime buffer WITHOUT draining — check is non-destructive
|
|
1431
1432
|
realtime_buffered = _REALTIME.peek() if _REALTIME else []
|
|
1432
1433
|
# Don't mark as seen — meshcode_check is a peek, not a consume
|
|
@@ -2079,7 +2080,15 @@ def history_resource() -> str:
|
|
|
2079
2080
|
# ============================================================
|
|
2080
2081
|
|
|
2081
2082
|
def _auto_update() -> None:
|
|
2082
|
-
"""
|
|
2083
|
+
"""Upgrade meshcode from PyPI in background — opt-in via MESHCODE_AUTO_UPDATE=1.
|
|
2084
|
+
|
|
2085
|
+
Disabled by default to mitigate supply chain risk: if the PyPI account
|
|
2086
|
+
is compromised, every agent would silently install malicious code.
|
|
2087
|
+
"""
|
|
2088
|
+
if os.environ.get("MESHCODE_AUTO_UPDATE", "0") != "1":
|
|
2089
|
+
log.debug("[meshcode] Auto-update disabled (set MESHCODE_AUTO_UPDATE=1 to enable)")
|
|
2090
|
+
return
|
|
2091
|
+
|
|
2083
2092
|
import threading
|
|
2084
2093
|
|
|
2085
2094
|
def _upgrade():
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|