watch.js
1 import { cli, Strategy } from '@jackwener/opencli/registry'; 2 export const watchCommand = cli({ 3 site: 'antigravity', 4 name: 'watch', 5 description: 'Stream new chat messages from Antigravity in real-time', 6 domain: 'localhost', 7 strategy: Strategy.UI, 8 browser: true, 9 args: [], 10 timeoutSeconds: 86400, // Run for up to 24 hours 11 columns: [], // We use direct stdout streaming 12 func: async (page) => { 13 console.log('Watching Antigravity chat... (Press Ctrl+C to stop)'); 14 let lastLength = 0; 15 // Loop until process gets killed 16 while (true) { 17 const text = await page.evaluate(` 18 async () => { 19 const container = document.getElementById('conversation'); 20 return container ? container.innerText : ''; 21 } 22 `); 23 const currentLength = text.length; 24 if (currentLength > lastLength) { 25 // Delta mode 26 const newSegment = text.substring(lastLength); 27 if (newSegment.trim().length > 0) { 28 process.stdout.write(newSegment); 29 } 30 lastLength = currentLength; 31 } 32 else if (currentLength < lastLength) { 33 // The conversation was cleared or updated significantly 34 lastLength = currentLength; 35 console.log('\\n--- Conversation Cleared/Changed ---\\n'); 36 process.stdout.write(text); 37 } 38 await new Promise(resolve => setTimeout(resolve, 500)); 39 } 40 }, 41 });