/ clis / cursor / composer.js
composer.js
 1  import { cli, Strategy } from '@jackwener/opencli/registry';
 2  import { SelectorError } from '@jackwener/opencli/errors';
 3  export const composerCommand = cli({
 4      site: 'cursor',
 5      name: 'composer',
 6      description: 'Send a prompt directly into Cursor Composer (Cmd+I shortcut)',
 7      domain: 'localhost',
 8      strategy: Strategy.UI,
 9      browser: true,
10      args: [{ name: 'text', required: true, positional: true, help: 'Text to send into Composer' }],
11      columns: ['Status', 'InjectedText'],
12      func: async (page, kwargs) => {
13          const textToInsert = kwargs.text;
14          // Open/Focus Composer via shortcut — always works regardless of current state
15          await page.pressKey('Meta+I');
16          await page.wait(1);
17          const typed = await page.evaluate(`(function(text) {
18          let composer = document.activeElement;
19          if (!composer || !composer.isContentEditable) {
20              composer = document.querySelector('.composer-bar [data-lexical-editor="true"], [id*="composer"] [contenteditable="true"], .aislash-editor-input');
21          }
22          
23          if (!composer) return false;
24  
25          composer.focus();
26          document.execCommand('insertText', false, text);
27          return true;
28        })(${JSON.stringify(textToInsert)})`);
29          if (!typed) {
30              throw new SelectorError('Cursor Composer input element', 'Could not find Cursor Composer input element after pressing Cmd+I.');
31          }
32          await page.wait(0.5);
33          await page.pressKey('Enter');
34          await page.wait(1);
35          return [
36              {
37                  Status: 'Success',
38                  InjectedText: textToInsert,
39              },
40          ];
41      },
42  });