history.js
1 import { cli, Strategy } from '@jackwener/opencli/registry'; 2 export const historyCommand = cli({ 3 site: 'cursor', 4 name: 'history', 5 description: 'List recent chat sessions from the Cursor sidebar', 6 domain: 'localhost', 7 strategy: Strategy.UI, 8 browser: true, 9 args: [], 10 columns: ['Index', 'Title'], 11 func: async (page) => { 12 const items = await page.evaluate(` 13 (function() { 14 const results = []; 15 // Cursor chat history lives in sidebar items 16 const entries = document.querySelectorAll('.agent-sidebar-list-item, [data-testid="chat-history-item"], .chat-history-item, .tree-item'); 17 18 entries.forEach((item, i) => { 19 const title = (item.textContent || item.innerText || '').trim().substring(0, 100); 20 if (title) results.push({ Index: i + 1, Title: title }); 21 }); 22 23 // Fallback: try to find sidebar text items 24 if (results.length === 0) { 25 const sidebar = document.querySelector('.sidebar, [class*="sidebar"], .agent-sidebar, .side-bar-container'); 26 if (sidebar) { 27 const links = sidebar.querySelectorAll('a, [role="treeitem"], [role="option"]'); 28 links.forEach((link, i) => { 29 const text = (link.textContent || '').trim().substring(0, 100); 30 if (text) results.push({ Index: i + 1, Title: text }); 31 }); 32 } 33 } 34 35 return results; 36 })() 37 `); 38 if (items.length === 0) { 39 return [{ Index: 0, Title: 'No chat history found. Open the AI sidebar first.' }]; 40 } 41 return items; 42 }, 43 });