read.js
1 import { cli, Strategy } from '@jackwener/opencli/registry'; 2 import { EmptyResultError } from '@jackwener/opencli/errors'; 3 export const readCommand = cli({ 4 site: 'cursor', 5 name: 'read', 6 description: 'Read the current Cursor chat/composer conversation history', 7 domain: 'localhost', 8 strategy: Strategy.UI, 9 browser: true, 10 columns: ['Role', 'Text'], 11 func: async (page) => { 12 const history = await page.evaluate(` 13 (function() { 14 const messages = Array.from(document.querySelectorAll('[data-message-role]')); 15 16 if (messages.length === 0) { 17 return []; 18 } 19 20 return messages.map(msg => { 21 const role = msg.getAttribute('data-message-role'); 22 let text = ''; 23 24 // Try to get structured markdown root for AI, or lexical text for human 25 const markdownRoot = msg.querySelector('.markdown-root'); 26 if (markdownRoot) { 27 text = markdownRoot.innerText || markdownRoot.textContent; 28 } else { 29 text = msg.innerText || msg.textContent; 30 } 31 32 return { 33 Role: role === 'human' ? 'User' : 'Assistant', 34 Text: text.trim() 35 }; 36 }); 37 })() 38 `); 39 if (!history || history.length === 0) { 40 throw new EmptyResultError('cursor read', 'No conversation history found in Cursor.'); 41 } 42 return history; 43 }, 44 });