feat(hybrid-gateway): integrate muse-cli with Cloudflare netns isolation, symmetric sidechat routing, and 646-pip sync unblock

This commit is contained in:
operator
2026-10-04 22:54:01 +00:00
parent 3d5fbe5aeb
commit 1a271b1bbd
60 changed files with 5068 additions and 55 deletions
+26 -6
View File
@@ -42,6 +42,8 @@ from datetime import datetime, timezone
BASE = "/home/super/Projects/NetVM"
BIN = os.path.join(BASE, "bin")
if BIN not in sys.path:
sys.path.insert(0, BIN)
BOX_CHAT = os.path.join(BIN, "box-chat.py")
DM_PY = os.path.join(BIN, "dm.py")
STATE_FILE = os.path.join(BASE, "self-main-loop-watermark.json")
@@ -132,7 +134,25 @@ def get_config(st):
def read_main_chat(agent, limit):
"""Read agent's muse.ai Main chat via box-chat.py. Returns (ok, messages|error)."""
"""Read agent's muse.ai Main chat. Tries fast headless gateway (muse_hybrid) first, falling back to box-chat.py."""
# Fast path: muse_hybrid over WebSocket Noise frame inside isolated netns
try:
import muse_hybrid
msgs, err = muse_hybrid.get_history(agent, thread_id=None, limit=limit)
if msgs and not err:
formatted = []
for m in msgs:
formatted.append({
"id": m.get("message_id") or f"msg-{m.get('seq')}",
"ts": None,
"from": {"name": m.get("role", "unknown")},
"text": m.get("text", "")
})
return True, formatted
except Exception:
pass
# Fallback to box-chat.py / CDP if gateway fails or returns empty
cmd = [sys.executable, BOX_CHAT, "thread-messages", agent, "main",
"--limit", str(limit)]
try:
@@ -172,16 +192,16 @@ def author_of(m):
def compose_digest(agent, new):
"""Concise, actionable digest for the prompting sidechat."""
lines = ["[main-loop] %d new in %s main chat:" % (len(new), agent)]
"""Concise, actionable digest for the prompting sidechat without synthetic ceremony."""
lines = ["New messages in %s main chat (%d):" % (agent, len(new))]
for m in new[:5]:
text = (m.get("text") or "").strip().replace("\n", " ")
q = " [?]" if "?" in text else ""
hot = " [!]" if (OPERATOR_RE.search(text) or "urgent" in text.lower()) else ""
q = " (?)" if "?" in text else ""
hot = " (!)" if (OPERATOR_RE.search(text) or "urgent" in text.lower()) else ""
lines.append("- %s: %s%s%s" % (author_of(m), text[:PREVIEW_MAX], q, hot))
if len(new) > 5:
lines.append("(+%d more)" % (len(new) - 5))
lines.append("Check main chat via box when you can.")
lines.append("Check main chat via box when available.")
digest = "\n".join(lines)
return digest[:DIGEST_MAX]