CDP Switches Cursor Agents in 10ms: Multi-Agent Patrol via Chrome DevTools Protocol #1
joinwell52-AI
started this conversation in
Show and tell
Replies: 1 comment
-
📄 Bilingual Documentation / 中英文双语文档The full CDP technical documentation is now available in both languages: 🇺🇸 English: CDP Multi-Agent Differentiation Mechanism 🇨🇳 中文: CDP 多 Agent 区分机制 Both documents cover the complete CDP architecture: two-layer DOM scanning, real-time coordinate switching, 3-layer busy detection, graceful OCR degradation, and Cursor upgrade resilience. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Why CDP for Cursor Agent Patrol?
We built CodeFlow to orchestrate multi-role AI teams (PM/DEV/QA/OPS) in Cursor IDE. The biggest challenge? Monitoring and switching between agents reliably.
Our first approach was OCR — screenshot the screen, run image recognition, guess which agent is active. It worked, but poorly:
aria-selected=trueexact matchpyautogui.click(x, y)screen coordsInput.dispatchMouseEventwindow coordsSo we rebuilt everything on Chrome DevTools Protocol.
How It Works
Cursor runs on Electron, which means it supports
--remote-debugging-port=9222. Once enabled, we get full DOM access.Two-Layer Agent Scanning
Layer 1 — Tab bar:
document.querySelectorAll('div[role=tab]')/^\s*(\d{1,2})[\s\-\.]+([A-Za-z][A-Za-z0-9\-]+)\s*$/01-PM,02-DEV,03-QA,04-OPSaria-selected === trueLayer 2 — Agent sidebar:
document.querySelectorAll('span.agent-sidebar-cell-text')Agent Switching with Native Mouse Events
Every switch uses real-time coordinates (never cached — tabs move with window resize, sidebar toggle, DPI):
getBoundingClientRect()center pointInput.dispatchMouseEvent: mousePressed + mouseReleased (notel.click()— Electron/React may swallow synthetic events)scan()after 500ms confirmsagentRolematches target3-Layer Busy Detection
Before sending any message, we check if the target agent is working:
button[aria-label=Cancel],button[aria-label=Stop]— visible = busy[class*=animate-spin]within Composer area only (excludes global loading)generating,thinking,planning,running terminal,applying patch,searchingIf busy: defer nudge, put back in queue, retry next patrol cycle.
Message Sending (Bypassing React Controlled Components)
nativeInputValueSetterto bypass React controlled component -> triggerinputeventInput.insertText(CDP native text insertion)Input.dispatchKeyEvent(keyDown + keyUp, key=Enter)Graceful Degradation
Every CDP step auto-falls back to OCR:
Any CDP step fails |-- Port unreachable -> entire cycle uses OCR |-- Connection dropped -> this cycle uses OCR, auto-reconnect next |-- Role not found -> this role uses OCR |-- Click verify failed -> this role retries with OCR |-- Send failed -> send step uses OCR OCR also fails? -> Retry queue, next patrol cycle -> Dashboard shows failure statusFull Technical Documentation
Read the complete 400+ line deep-dive: CDP Multi-Agent Documentation
Source code: cursor_cdp.py
Questions, feedback, or ideas for improvement? Drop a comment below!
Beta Was this translation helpful? Give feedback.
All reactions