From 87fd93e7a6c8c562268e7bc8eb215f076b4b7078 Mon Sep 17 00:00:00 2001 From: operator Date: Sun, 4 Oct 2026 16:39:23 +0000 Subject: [PATCH] feat(dm): implement Reset-at-Begin and Leave-in-Sidechat pattern to preserve Main Chat DOM --- bin/dm.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bin/dm.py b/bin/dm.py index 88b2a5c..9da54fe 100755 --- a/bin/dm.py +++ b/bin/dm.py @@ -303,6 +303,11 @@ def dm_send(agent, target, message, verify=True, raw=False, if target == "main": _rc, _out, _err = run_full(f"{NETVM_EXEC} {recipient} -- python3 {API} --account {recipient} sidechat main") else: + # Reset-at-Begin: If searching sidebar by title (not a direct UUID), reset to main first to expose the sidebar + is_uuid = bool(re.fullmatch(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", nav_target.strip().lower())) + if not is_uuid: + run_full(f"{NETVM_EXEC} {recipient} -- python3 {API} --account {recipient} sidechat main") + time.sleep(1) _rc, _out, _err = run_full(f"{NETVM_EXEC} {recipient} -- python3 {API} --account {recipient} sidechat use {nav_target}") if _rc != 0: log_event({"type": "nav_failed", "id": msg_id, "agent": agent, "to": recipient, @@ -451,9 +456,7 @@ def dm_send(agent, target, message, verify=True, raw=False, if delivered and thread_uuid and "thread" not in tags: tags["thread"] = thread_uuid - # Park the recipient's browser back on main - run(f"{NETVM_EXEC} {recipient} -- python3 {API} --account {recipient} sidechat main") - + # Note: Leave recipient browser parked in the sidechat thread to preserve Main Chat DOM log_event({"type": "send_done", "id": msg_id, "agent": agent, "to": recipient, "target": target}) if delivered: @@ -484,11 +487,14 @@ def dm_read(agent, target, n=5, quiet=False, width=200): if target == "main": run(f"{NETVM_EXEC} {agent} -- python3 {API} --account {agent} sidechat main") else: + is_uuid = bool(re.fullmatch(r"[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", nav_target.strip().lower())) + if not is_uuid: + run(f"{NETVM_EXEC} {agent} -- python3 {API} --account {agent} sidechat main") + time.sleep(1) run(f"{NETVM_EXEC} {agent} -- python3 {API} --account {agent} sidechat use {nav_target}") time.sleep(2) rc, msgs, err = run_full(f"{NETVM_EXEC} {agent} -- python3 {API} --account {agent} messages {n} {width}") - run(f"{NETVM_EXEC} {agent} -- python3 {API} --account {agent} sidechat main") if rc != 0 or not msgs: # Never fail silently: an empty read with exit 0 hid a dead browser