/ clis / cursor / send.js
send.js
 1  import { cli, Strategy } from '@jackwener/opencli/registry';
 2  import { SelectorError } from '@jackwener/opencli/errors';
 3  export const sendCommand = cli({
 4      site: 'cursor',
 5      name: 'send',
 6      description: 'Send a prompt directly into Cursor Composer/Chat',
 7      domain: 'localhost',
 8      strategy: Strategy.UI,
 9      browser: true,
10      args: [{ name: 'text', required: true, positional: true, help: 'Text to send into Cursor' }],
11      columns: ['Status', 'InjectedText'],
12      func: async (page, kwargs) => {
13          const textToInsert = kwargs.text;
14          const injected = await page.evaluate(`(function(text) {
15          // Find the Lexical editor input for Composer or Chat
16          let composer = document.querySelector('.aislash-editor-input, [data-lexical-editor="true"], [contenteditable="true"]');
17          
18          if (!composer) {
19              return false;
20          }
21  
22          composer.focus();
23          document.execCommand('insertText', false, text);
24          return true;
25        })(${JSON.stringify(textToInsert)})`);
26          if (!injected) {
27              throw new SelectorError('Cursor Composer input element');
28          }
29          // Submit the command. In Cursor, Enter usually submits the chat.
30          await page.wait(0.5);
31          await page.pressKey('Enter');
32          await page.wait(1);
33          return [
34              {
35                  Status: 'Success',
36                  InjectedText: textToInsert,
37              },
38          ];
39      },
40  });