From 828f67ffc892de399fe4f1e391eed9ee25930c35 Mon Sep 17 00:00:00 2001 From: operator Date: Sat, 3 Oct 2026 19:21:04 +0000 Subject: [PATCH] p2p-relay: 646 to muse via headless --- bin/p2p-relay.py | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100755 bin/p2p-relay.py diff --git a/bin/p2p-relay.py b/bin/p2p-relay.py new file mode 100755 index 0000000..b994c77 --- /dev/null +++ b/bin/p2p-relay.py @@ -0,0 +1,56 @@ +#!/usr/bin/env python3 +""" +P2P Relay: 646 -> muse via headless + +Reads from 646's p2p-muse-outbox, writes to muse's p2p-646-inbox. +Usage: p2p-relay.py [--once] [--daemon] +""" +import subprocess +import sys +import time + +API = "~/Projects/NetVM/bin/muse-chat-api.py" +EXEC_646 = "~/Projects/NetVM/bin/netvm-exec.sh 646 --" +EXEC_MUSE = "~/Projects/NetVM/bin/netvm-exec.sh muse --" + +OUTBOX_646 = "3ed3aef3-2d92-408c-9e13-f36e40a75976" +INBOX_MUSE = "6db43088-b87d-43a3-ae2a-157acebcfa21" + +def run(cmd): + result = subprocess.run(cmd, shell=True, capture_output=True, text=True) + return result.stdout.strip() + +def get_outbox_messages(): + # Navigate 646 to outbox, read messages + run(f"{EXEC_646} python3 {API} --account 646 sidechat use {OUTBOX_646}") + time.sleep(2) + msgs = run(f"{EXEC_646} python3 {API} --account 646 messages 5") + run(f"{EXEC_646} python3 {API} --account 646 sidechat main") + return msgs + +def send_to_muse(message): + # Navigate muse to inbox, send message + run(f"{EXEC_MUSE} python3 {API} --account muse sidechat use {INBOX_MUSE}") + time.sleep(2) + run(f"{EXEC_MUSE} python3 {API} --account muse send \"{message}\"") + run(f"{EXEC_MUSE} python3 {API} --account muse sidechat main") + +def relay_once(): + msgs = get_outbox_messages() + # Simple: if there are messages, relay the latest + # In production, track watermark to avoid duplicates + if msgs and "P2P setup" not in msgs: + # Extract last message (crude) + lines = [l for l in msgs.split('\n') if l.strip() and '---' not in l] + if lines: + latest = lines[-1][:500] + print(f"Relaying: {latest[:80]}...") + send_to_muse(f"[from 646] {latest}") + return True + return False + +if __name__ == '__main__': + if '--once' in sys.argv: + relay_once() + else: + print("Use --once for single relay")