#!/usr/bin/env python3 """ dev-dm.py: Developer Direct Messages For operator-to-developer communication (muse, pip task agents). Developers are browser-only, no SSH. Uses headless via dm.py backend. Distinct from opp-dm.py (for operators: 646, operator-main). Usage: dev-dm.py send --agent muse --target main "message" dev-dm.py read --agent muse --target main """ import argparse import subprocess import sys DM_PY = "/home/super/Projects/NetVM/bin/dm.py" def run(cmd, timeout=90): result = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=timeout) return result.stdout.strip() def dev_send(agent, target, message): """Send a dev DM via headless (dm.py backend).""" if agent not in ["muse", "pip"]: print(f"ERROR: dev-dm only for muse, pip (not {agent})", file=sys.stderr) sys.exit(1) # Delegate to dm.py safe = message.replace('"', '\\"')[:1000] cmd = f"{DM_PY} send --agent {agent} --target {target} \"{safe}\"" # Run on bl bl_cmd = f"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes super@100.123.153.75 '{cmd}'" vm_cmd = f"ssh -i ~/.ssh/vm_to_gcp -o ProxyCommand=\"$HOME/workspace/bin/ssh-via-proxy %h %p\" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes super@34.139.37.135 \"{bl_cmd}\"" result = run(vm_cmd) print(f"DEV-DM sent to {agent}/{target}") return result def dev_read(agent, target, n=5): """Read dev DMs via headless.""" if agent not in ["muse", "pip"]: print(f"ERROR: dev-dm only for muse, pip", file=sys.stderr) sys.exit(1) cmd = f"{DM_PY} read --agent {agent} --target {target} --n {n}" bl_cmd = f"ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes super@100.123.153.75 '{cmd}'" vm_cmd = f"ssh -i ~/.ssh/vm_to_gcp -o ProxyCommand=\"$HOME/workspace/bin/ssh-via-proxy %h %p\" -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o BatchMode=yes super@34.139.37.135 \"{bl_cmd}\"" result = run(vm_cmd) print(result) return result def main(): p = argparse.ArgumentParser(description="DEV-DM: Developer Direct Messages") sub = p.add_subparsers(dest='cmd', required=True) ps = sub.add_parser('send', help='Send dev DM') ps.add_argument('--agent', required=True, choices=['muse', 'pip']) ps.add_argument('--target', required=True, help='main or chat_id') ps.add_argument('message', help='Message') ps.set_defaults(func=lambda a: dev_send(a.agent, a.target, a.message)) pr = sub.add_parser('read', help='Read dev DMs') pr.add_argument('--agent', required=True, choices=['muse', 'pip']) pr.add_argument('--target', required=True) pr.add_argument('--n', type=int, default=5) pr.set_defaults(func=lambda a: dev_read(a.agent, a.target, a.n)) args = p.parse_args() args.func(args) if __name__ == '__main__': main()