cmd_sidechat_create: exact header check for panel state\n\ninnerText.includes was always true (switcher button text).\nNow checks for exact Side chats header text node, loops up to 5x.

This commit is contained in:
operator-main
2026-10-04 03:38:22 +00:00
parent 8ff4dd0e30
commit f8b6475396
+22 -11
View File
@@ -270,20 +270,31 @@ def cmd_sidechat_create(ws):
- + button: [data-testid="hatch-chat-compose"] (SVG icon, no text) - + button: [data-testid="hatch-chat-compose"] (SVG icon, no text)
""" """
import time as _time import time as _time
# Check if + button already present (panel open). If not, open via switcher. # Check if panel is open via exact 'Side chats' header text node.
# Fixed 2026-10-04: don't blindly click switcher, check state first. # (Not innerText.includes - the switcher button text contains "Open chat and
has_plus = ev(ws, """(() => { # side chats" which is always true. Must check for the header element.)
return !!document.querySelector('[data-testid="hatch-chat-compose"]'); # Then open via switcher if needed (loop up to 5 attempts).
})()""") # Fixed 2026-10-04 per chat panel investigation.
if not has_plus: def _panel_open():
# Panel closed, open via switcher trigger return ev(ws, """(() => {
sw_result = ev(ws, """(() => { const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
let n;
while (n = walker.nextNode()) {
if (n.textContent.trim() === 'Side chats') return true;
}
return false;
})()""")
for _attempt in range(5):
if _panel_open():
break
ev(ws, """(() => {
const sw = document.querySelector('[data-testid="hatch-chat-switcher-trigger"]'); const sw = document.querySelector('[data-testid="hatch-chat-switcher-trigger"]');
if (sw) sw.click(); if (sw) sw.click();
return sw ? 'SWITCHER_CLICKED' : 'NO_SWITCHER';
})()""") })()""")
print(f"Switcher: {sw_result}", file=sys.stderr) _time.sleep(3)
_time.sleep(2) # Wait for React render else:
print("Warning: panel may not be open after 5 attempts", file=sys.stderr)
# Find + button via data-testid (verified selector, SVG icon no text) # Find + button via data-testid (verified selector, SVG icon no text)
result = ev(ws, """(() => { result = ev(ws, """(() => {
const btn = document.querySelector('[data-testid="hatch-chat-compose"]'); const btn = document.querySelector('[data-testid="hatch-chat-compose"]');