chore(legacy): archive early prototype listener and relay scripts

This commit is contained in:
operator
2026-10-07 01:49:48 +00:00
parent 3c6bfa5120
commit a09337ec48
4 changed files with 12 additions and 0 deletions
+12
View File
@@ -0,0 +1,12 @@
# Legacy / Archived Scripts
This directory preserves early prototype scripts from the initial NetVM setup (2026-10-03).
These have been superseded by unified fleet orchestration tools in `bin/`.
## Archived Modules
| File | Original Role | Superseded By |
| :--- | :--- | :--- |
| `dm-listener.py` | Polled 646's main chat for `Message <agent>:` patterns and routed them | [`bin/dm.py`](../bin/dm.py) & [`bin/box-ctl.py`](../bin/box-ctl.py) (`box dm send` / `box-chat`) |
| `thread-listener.py` | Executed `THREAD <agent> <id> <msg>` commands found in main chat | [`bin/box-ctl.py`](../bin/box-ctl.py) (`box thread list/view`) & [`bin/muse-chat-api.py`](../bin/muse-chat-api.py) |
| `p2p-relay.py` | Relayed outbox messages from 646 to muse | Sidechat routing via [`bin/dm.py`](../bin/dm.py) and [`bin/self_main_loop.py`](../bin/self_main_loop.py) |
+84
View File
@@ -0,0 +1,84 @@
#!/usr/bin/env python3
"""
DM listener: Auto-routes 646's "Message <agent>:" requests
Watches 646's main chat for "Message <agent>: <text>" patterns,
routes via dm.py automatically.
This makes 646's DM "work" — she says who, the system handles how.
"""
import subprocess
import time
import json
import re
from pathlib import Path
DM_PY = "/home/super/Projects/NetVM/bin/dm.py"
NETVM_EXEC = "/home/super/Projects/NetVM/bin/netvm-exec.sh"
API = "/home/super/Projects/NetVM/bin/muse-chat-api.py"
WATERMARK_FILE = Path("/home/super/Projects/NetVM/bridge/dm-listener-watermark.json")
VALID_AGENTS = ["muse", "pip", "646"]
def load_watermark():
if WATERMARK_FILE.exists():
with open(WATERMARK_FILE) as f:
return json.load(f)
return {"processed": []}
def save_watermark(data):
WATERMARK_FILE.parent.mkdir(parents=True, exist_ok=True)
with open(WATERMARK_FILE, 'w') as f:
json.dump(data, f, indent=2)
def run(cmd, timeout=60):
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=timeout)
return result.stdout.strip()
def get_646_messages():
return run(f"{NETVM_EXEC} 646 -- python3 {API} --account 646 messages 5")
def poll_once():
wm = load_watermark()
msgs = get_646_messages()
parts = [p.strip() for p in msgs.split('---') if p.strip()]
for part in parts:
# Match "Message <agent>: <text>"
m = re.match(r'Message\s+(\w+)\s*:\s*(.+)', part, re.DOTALL | re.IGNORECASE)
if m:
agent, text = m.groups()
agent = agent.lower()
text = text.strip()
if agent not in VALID_AGENTS:
continue
# Deduplicate
cmd_id = f"{agent}:{text[:40]}"
if cmd_id in wm["processed"]:
continue
print(f"Routing: 646 -> {agent}: {text[:60]}...")
# Route via dm.py (sends to agent's main chat)
run(f"{DM_PY} send --agent {agent} --target main \"[646] {text[:800]}\"")
wm["processed"].append(cmd_id)
# Keep only last 20 to avoid unbounded growth
wm["processed"] = wm["processed"][-20:]
save_watermark(wm)
print("Routed.")
if __name__ == '__main__':
import sys
if '--once' in sys.argv:
poll_once()
elif '--daemon' in sys.argv:
print("DM listener running...")
while True:
try:
poll_once()
except Exception as e:
print(f"Error: {e}")
time.sleep(30)
else:
print("Use --once or --daemon")
+95
View File
@@ -0,0 +1,95 @@
#!/usr/bin/env python3
"""
P2P Relay: 646 -> muse via headless (with watermark)
Reads from 646's p2p-muse-outbox, writes to muse's p2p-646-inbox.
Tracks watermark to avoid duplicate relays.
Usage: p2p-relay.py [--once]
Watermark: ~/Projects/NetVM/bridge/p2p-watermark.json
"""
import subprocess
import sys
import time
import json
import hashlib
from pathlib import Path
API = "/home/super/Projects/NetVM/bin/muse-chat-api.py"
EXEC_646 = "/home/super/Projects/NetVM/bin/netvm-exec.sh 646 --"
EXEC_MUSE = "/home/super/Projects/NetVM/bin/netvm-exec.sh muse --"
OUTBOX_646 = "3ed3aef3-2d92-408c-9e13-f36e40a75976"
INBOX_MUSE = "6db43088-b87d-43a3-ae2a-157acebcfa21"
WATERMARK_FILE = Path("/home/super/Projects/NetVM/bridge/p2p-watermark.json")
def load_watermark():
if WATERMARK_FILE.exists():
with open(WATERMARK_FILE) as f:
return json.load(f)
return {"last_hash": None, "last_relay": None}
def save_watermark(data):
WATERMARK_FILE.parent.mkdir(parents=True, exist_ok=True)
with open(WATERMARK_FILE, 'w') as f:
json.dump(data, f, indent=2)
def run(cmd):
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=60)
return result.stdout.strip()
def get_outbox_messages():
run(f"{EXEC_646} python3 {API} --account 646 sidechat use {OUTBOX_646}")
time.sleep(3)
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):
run(f"{EXEC_MUSE} python3 {API} --account muse sidechat use {INBOX_MUSE}")
time.sleep(3)
# Escape for shell
safe = message.replace('"', '\\"').replace('$', '\\$').replace('`', '\\`')
run(f'{EXEC_MUSE} python3 {API} --account muse send "{safe}"')
run(f"{EXEC_MUSE} python3 {API} --account muse sidechat main")
def relay_once():
wm = load_watermark()
msgs = get_outbox_messages()
if not msgs or "P2P test" in msgs and "Hello muse" in msgs:
# Skip if only the test message (already relayed manually)
# Or if empty
pass
# Extract messages (split by ---)
parts = [p.strip() for p in msgs.split('---') if p.strip()]
# Filter out system messages
parts = [p for p in parts if p and len(p) > 10 and "P2P setup" not in p]
if not parts:
print("No new messages in outbox")
return False
latest = parts[-1]
msg_hash = hashlib.md5(latest.encode()).hexdigest()[:16]
if msg_hash == wm.get("last_hash"):
print("Already relayed (watermark match)")
return False
print(f"Relaying new message: {latest[:80]}...")
send_to_muse(f"[from 646] {latest[:500]}")
wm["last_hash"] = msg_hash
wm["last_relay"] = time.strftime("%Y-%m-%dT%H:%M:%S")
save_watermark(wm)
print("Relayed and watermark updated")
return True
if __name__ == '__main__':
if '--once' in sys.argv:
relay_once()
else:
print("Use --once for single relay")
+102
View File
@@ -0,0 +1,102 @@
#!/usr/bin/env python3
"""
THREAD listener: Auto-executes 646's THREAD commands
Polls 646's main chat for THREAD commands, executes via headless.
Format: THREAD <agent> <main|chat_id> <message>
Watermark prevents duplicate execution.
"""
import subprocess
import time
import json
import re
from pathlib import Path
API = "/home/super/Projects/NetVM/bin/muse-chat-api.py"
NETVM_EXEC = "/home/super/Projects/NetVM/bin/netvm-exec.sh"
WATERMARK_FILE = Path("/home/super/Projects/NetVM/bridge/thread-watermark.json")
def load_watermark():
if WATERMARK_FILE.exists():
with open(WATERMARK_FILE) as f:
return json.load(f)
return {"last_processed": None}
def save_watermark(data):
WATERMARK_FILE.parent.mkdir(parents=True, exist_ok=True)
with open(WATERMARK_FILE, 'w') as f:
json.dump(data, f, indent=2)
def run(cmd, timeout=60):
result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=timeout)
return result.stdout.strip()
def get_646_messages():
return run(f"{NETVM_EXEC} 646 -- python3 {API} --account 646 messages 5")
def execute_thread(agent, target, message):
"""Execute a THREAD command via headless."""
print(f"THREAD: {agent} -> {target}: {message[:60]}...")
# Navigate to target
if target == "main":
run(f"{NETVM_EXEC} {agent} -- python3 {API} --account {agent} sidechat main")
else:
# Assume it's a chat_id, navigate to thread
run(f"{NETVM_EXEC} {agent} -- python3 {API} --account {agent} sidechat use {target}")
time.sleep(2)
# Send message with 646 attribution
safe = message.replace('"', '\\"').replace('$', '\\$').replace('`', '\\`')[:500]
run(f'{NETVM_EXEC} {agent} -- python3 {API} --account {agent} send "[646] {safe}"')
# Back to main
run(f"{NETVM_EXEC} {agent} -- python3 {API} --account {agent} sidechat main")
print("Done")
def poll_once():
wm = load_watermark()
msgs = get_646_messages()
# Find THREAD commands (not yet processed)
# Simple: look for "THREAD " at start of a message part
parts = [p.strip() for p in msgs.split('---') if p.strip()]
for part in parts:
# Match THREAD <agent> <target> <message>
m = re.match(r'THREAD\s+(\w+)\s+(\w+)\s+(.+)', part, re.DOTALL)
if m:
agent, target, message = m.groups()
# Create a simple ID for deduplication
cmd_id = f"{agent}:{target}:{message[:30]}"
if cmd_id == wm.get("last_processed"):
continue # Already processed
# Validate agent
if agent not in ["muse", "pip", "646"]:
print(f"Unknown agent: {agent}, skipping")
continue
try:
execute_thread(agent, target, message.strip())
wm["last_processed"] = cmd_id
save_watermark(wm)
except Exception as e:
print(f"THREAD failed: {e}")
if __name__ == '__main__':
import sys
if '--once' in sys.argv:
poll_once()
elif '--daemon' in sys.argv:
print("THREAD listener running (poll every 60s)...")
while True:
try:
poll_once()
except Exception as e:
print(f"Poll error: {e}")
time.sleep(60)
else:
print("Use --once or --daemon")