/ clis / antigravity / extract-code.js
extract-code.js
 1  import { cli, Strategy } from '@jackwener/opencli/registry';
 2  export const extractCodeCommand = cli({
 3      site: 'antigravity',
 4      name: 'extract-code',
 5      description: 'Extract multi-line code blocks from the current Antigravity conversation',
 6      domain: 'localhost',
 7      strategy: Strategy.UI,
 8      browser: true,
 9      args: [],
10      columns: ['code'],
11      func: async (page) => {
12          const blocks = await page.evaluate(`
13        async () => {
14          // Find standard pre/code blocks
15          let elements = Array.from(document.querySelectorAll('pre code'));
16          
17          // Fallback to Monaco editor content inside the UI
18          if (elements.length === 0) {
19            elements = Array.from(document.querySelectorAll('.monaco-editor'));
20          }
21          
22          // Generic fallback to any code tag that spans multiple lines
23          if (elements.length === 0) {
24            elements = Array.from(document.querySelectorAll('code')).filter(c => c.innerText.includes('\\n'));
25          }
26          
27          return elements.map(el => el.innerText).filter(text => text.trim().length > 0);
28        }
29      `);
30          return blocks.map((code) => ({ code }));
31      },
32  });