feat(cursor): add chat command with CDP native key events#669
feat(cursor): add chat command with CDP native key events#669cjb2667 wants to merge 1 commit intojackwener:mainfrom
Conversation
- 使用 Cmd+N 打开新对话窗口(而非 Cmd+L) - 通过 CDP Input.dispatchKeyEvent 发送 Enter 键,解决 Cursor v2.6.22 Lexical 编辑器不响应 JS dispatchEvent 合成事件的问题 - 支持 --timeout 参数控制等待 AI 回复的超时时间(默认 60s) - 从 [data-message-role="ai"] 的 .markdown-root 提取回复文本 Made-with: Cursor
Astro-Han
left a comment
There was a problem hiding this comment.
A few concerns:
-
Why not fix the existing commands? The PR says
send/askbroke because Cursor's Lexical editor ignores synthetic JS keyboard events. The CDPInput.dispatchKeyEventfix here is the right technique, but it should be applied to the existingsend/askcommands rather than adding a parallelchatcommand that does the same thing differently. Users shouldn't need to know which command works with which Cursor version. -
(page as any).bridgebypasses the IPage abstraction.cdpPressEnterandcdpKeyComboreach into the CDPBridge internal instance directly. This only works in direct CDP mode — in daemon mode (the default),bridgedoesn't exist and this will throw at runtime with no useful error message. IfInput.dispatchKeyEventis needed, it should go through the IPage interface so both transport paths can support it. -
No tests. Even a basic unit test mocking the page object and verifying the call sequence (new chat → inject text → press Enter → poll for response) would catch regressions.
Summary
opencli cursor chat "prompt"command that opens a new Cursor chat session and sends a promptInput.dispatchKeyEventinstead of JSdispatchEventto submit messages, fixing compatibility with Cursor v2.6.22+ Lexical editor--timeoutparameter (default 60s) to control how long to wait for AI responseMotivation
The existing
sendandaskcommands use JavaScriptdispatchEvent(new KeyboardEvent(...))to simulate Enter key press. However, Cursor's Lexical editor (since v2.6+) does not respond to synthetic keyboard events — only CDP-level native input events trigger the submit action.This new
chatcommand:Cmd+N(the correct shortcut for new chat, notCmd+L)document.execCommand('insertText')Input.dispatchKeyEvent(keyDown + keyUp for Enter)[data-message-role="ai"]elementsTest plan
opencli cursor chat "请回复 hello world"→ AI respondsHello world!opencli cursor chat "请回复数字 42"→ AI responds42--timeout 120Made with Cursor