feat(dm): implement Reset-at-Begin and Leave-in-Sidechat pattern to preserve Main Chat DOM
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user